0

Look at this piece of my code:

             $(".field").editable("http://"+document.location.host+"/index.php/welcome/update_record", 
             {  
                event  : "mouseover",
                style  : "inherit",
                callback: function(value, settings) 
                {
                    //Some code
                }
             }

But I have some problems - this code works good for me, because it catches clicks by "enter" button. But now I need to change type of field to "textarea":

         $(".field").editable("http://"+document.location.host+"/index.php/welcome/update_record", 
         {  
            type : "textarea",
            event  : "mouseover",
            style  : "inherit",
            callback: function(value, settings) 
            {
                //Some code
            }
         }

And now it doesn't work - i.e. callback function has never executed. Please, tell me, I need to have textarea field and to catch event of pressing Enter.

4

2 回答 2

1

如果你想在按下回车时进行回调,你可以这样做:

http://jsfiddle.net/NRxLP/

$('#example').keyup(function(e) {
  if (e.which == 13) {
    $('#example').trigger('custom');
  } 
});

然后在 jEditable 中为您的处理程序捕获“自定义”事件。

但是,我不会将此称为最佳实践,用户习惯于使用文本区域中的输入按钮来添加多行。也许您也可以添加一个按钮 - 我相信 jEditable 有一种方法可以自动添加一个“保存”按钮..

在这个问题中 - jquery jeditable without OK and Cancel Buttons - 他们使用模糊事件,这对我来说更有意义..

于 2012-09-04T18:38:35.803 回答
0

我建议也检查 ctrl 和 shift 键,并防止默认行为是有一个:

$(this).bind('keydown', function () {
                if (event.keyCode === 13 && !event.shiftKey && !event.ctrlKey) {
                    event.preventDefault();
                    $(this.form).submit(); // Or whatever
                    return false;
                } 
            })
于 2018-10-06T20:09:08.523 回答