数据表上的jQuery设置按键
我使用的是datatables,对于编辑行,我现在可以在当前行上插入输入元素,我想在输入元素上设置enter键,但在绝对插入的jquery中不起作用 jquery:数据表上的jQuery设置按键,jquery,jquery-datatables,Jquery,Jquery Datatables,我使用的是datatables,对于编辑行,我现在可以在当前行上插入输入元素,我想在输入元素上设置enter键,但在绝对插入的jquery中不起作用 jquery: $("#showCategories tbody").dblclick(function(event) { var nTds_showCategories = $('td', this); $(oTable_categories.fnSettings().aoData).eac
$("#showCategories tbody").dblclick(function(event) {
var nTds_showCategories = $('td', this);
$(oTable_categories.fnSettings().aoData).each(function (){$(this.nTr).removeClass('row_selected');});
$(event.target.parentNode).addClass('row_selected');
current_category_text=$.trim( $(event.target).text() );
current_category_path=$(event.target);
$(event.target).html("<input value= '"+ $(event.target).text() +"' style='width:200px;float:right;height:17px;padding:0px;height:22px;padding-right:3px;' id='category_input_change' />");
$(event.target).append("<ul class='styledlist' style='width:50px;float:right;'><li style='line-height:13px;' id='save_category' >ذخیره</li></ul>");
$(event.target).append("<ul class='styledlist' style='width:50px;float:right;'><li style='line-height:13px;' id='cancel_save_category' >انصراف</li></ul>") ;
category_row_editable=false;
current_dlbclick=false;
event.returnValue= false;
return false;
}
});
2:
$('#category_input_change').bind('keypress', function(e) {
if(e.keyCode==13)
alert('ddddd');
});
$('#category_input_change').keyup(function (e) {
if (e.keyCode == 13)
alert('ddddd');
});
尝试使用。不要在category\u input\u change
上使用id
,因为id
必须是唯一的。改用class
像这样:
$("#showCategories").on('keyup', '.category_input_change', function(){
//your code here..
});
尝试使用
.live
或.on
方法,如
$('#category_input_change').live('keypress', function(e) {
if(e.keyCode==13)
alert('ddddd');
});
谢谢,但是我得到了这个错误:
TypeError:$(…).on不是一个函数
,我使用的是$(document).ready(函数(e){jQuery.noConflict();
也许你使用的是低于1.7的jQuery版本。你可以改用.live()
,但它已经被弃用了。这里是链接:我使用的是jQuery-1.9.1.min.js)
应该有效。请尝试将.noConflict()
放置在.ready()