"keydown”;以及“;改变“;事件不适用于jquery数据表

"keydown" and "change" events not working for jquery datatables

本文关键字:不适用 适用于 jquery 数据表 事件 改变 keydown 以及 quot      更新时间:2023-09-26

我在jquery数据表的每一行中都有一个输入字段。我必须在文本更改时触发一个事件,并为每个输入字段输入press。正在使用服务器端处理加载jquery数据表。在没有使用服务器端处理之前,输入字段事件运行良好!。是什么导致事件现在保持沉默?

我以前使用过的事件---

$('#txtQty').keydown(function (e) {
        alert("keydown");
}
$('#txtQty').change(function () {
         alert("Change");
}

在应用了服务器端处理之后,我使用了相同的侦听器。

Jquery网格详细信息-客户端处理和添加输入框~

@foreach (var item in Model)
{
 <tr>
                    .
.
.
.
.
.
@if (item.Qty <= 0)
{
 <td>
     <input class="inputs" id="txtQty" type="text" value=@item.MinQty />
     </td>
    }
  }

服务器端处理和输入框应用于移动-

$('#grid').dataTable({
        "bServerSide": true,
        "sAjaxSource": "../myaction/AjaxHandler",
        "bProcessing": true,
        "scrollY": 385,
        "scrollX": true,
        "scrollCollapse": true,
        "jQueryUI": true,
        "bJQueryUI": true,
        "sDom": 'lfrtip',
        "aoColumns": [
                        { "sName": "dfgdfg" },
                        { "sName": "dfgdfg" },
                        { "sName": "hhh" },
                        {
                            "sName": "Qty",
                            "mRender": function (sName) {
                                return '<input class="inputs" id="txtQty" type="text"  value='+ sName +' />';
                            },
                        },
                        { "sName": "Category" },
                        { "sName": "Comment" }
        ],
        "oLanguage": {
            "sProcessing":'Processing.....'
        }
    });
  • 您有多个具有相同id txtQty的元素。为了正确处理多个元素的事件,可以使用类。例如,类inputs

  • 对于动态创建的图元,可以使用$(document).on("event", "selector", function() {});

所以,最后,它应该看起来像:

$(document).on('keydown', '.inputs', function(e) {
    alert("keydown");
}
$(document).on('change', '.inputs', function() {
    alert("Change");
}

我想每页有不止一个"txtQty",所以使用类而不是id

 <input class="inputs txtQty" type="text" value=@item.MinQty />


$('.txtQty').keydown(function (e) {
    alert("keydown");
}
$('.txtQty').change(function () {
     alert("Change");
}