以jquery插件开发的方法开发。具体代码如下:
jQuery.fn.extend({
/**
* ctrl+enter提交表单
* @param {Function} fn 操作后执行的函数
* @param {Object} thisObj 指针作用域
*/
ctrlSubmit:function(fn,thisObj){
var obj = thisObj || this;
var stat = false;
return this.each(function(){
$(this).keyup(function(event){
//只按下ctrl情况,等待enter键的按下
if(event.keyCode == 17){
stat = true;
//取消等待
setTimeout(function(){
stat = false;
},300);
}
if(event.keyCode == 13 && (stat || event.ctrlKey)){
fn.call(obj,event);
}
});
});
}
});
使用方法:
$("#textarea").ctrlSubmit(function(event){
//提交代码写在这里
});
是不是非常的简单实用呢,希望大家能够喜欢。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号