我有一个MVC网站,我有一个html表,双击一个单元格,它将进入编辑模式,这是第一次工作,下次当我加倍在同一个单元格或任何其他单元格上不管怎样,当我在任何地方点击一下然后如果我双击它就可以了。
我怀疑单击和双击之间存在冲突。
$('#TableOverride tr:gt(0)').each(function () {
$(this).find('td:eq(9)').dblclick(function () {
EditCell(this, 9);
});
});
更新:在Chrome中测试过,它运行正常,没有任何问题,它看起来像IE 11及更早版本的浏览器问题。
function EditCell(thisCell, colNum) {
var Id;
// if the table cell is not in edit mode
if ($(thisCell).find('input').length == 0) {
if (colNum == 4 && $(thisCell).parent().parent().parent()[0].id == 'OverrideTable') {
myBlk = $(thisCell).html();
$(thisCell).html('<input type="text" data-oldvalue="' + myBlk + '" />');
$(thisCell).find('input').val(myBlk);
$(thisCell).find('input').trigger('focus');
$(thisCell).find('input').keypress(function (e) {
if (e.which == 13) {
// If Enter key is pressed, update data.
myBlk = $(this).val();
if (myBlk == '') {
$('div.errorSummary').html('my block cannot be empty!');
$('div.errorSummary').show();
} else {
Loadmyblk(myBlk, this);
LeaseOverrideObj.GetLeaseOverride());
}
});
}
答案 0 :(得分:0)
试试这个,它应该可行,添加自定义类,例如&#34; EditableCell&#34;用于在文档中使用dblclick事件绑定。
$('#TableOverride tr:gt(0)').each(
function () {
$(this).find('td:eq(9)').removeClass('EditableCell').addClass('EditableCell');
});
});
$(document).on('dblclick', '.EditableCell', function()
{ EditCell(this, 9);
});
请注意$(document).on
不应在任何循环中调用,只应在document.ready
中调用一次。
已更新 fiddle link to demo dblclick on dynamically added events