以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){
   //提交代码写在这里
});

相关文章:

  • 2021-05-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2021-08-31
  • 2021-08-19
  • 2022-12-23
  • 2021-11-14
  • 2021-11-21
相关资源
相似解决方案