1

我用 jquery 编写了以下代码:

$('input[type="text"]').keyup(
    function (event) {
        // Allow: backspace, delete, tab, escape, and enter
        if (event.keyCode != 68 && event.keyCode != 186) return;
        var textbox = $(this);
        var clickAttr = textbox.attr('click');
        if (clickAttr != undefined && clickAttr.indexOf('NumericTextBoxKeyPress') > -1) return; 
        var insertedValue = textbox.val();
        insertedValue = insertedValue.replace(/a/g, 'SampleA');
        insertedValue = insertedValue.replace(/b/g, 'SampleB');
        textbox.val(insertedValue);
    }
);

普通文本框没问题,但上面的代码不适用于 jQGrid 过滤的文本框!

将函数绑定到 jQGrid 过滤的文本框

您能否指导我,如何将 keyup 函数绑定到 jQGrid 过滤的文本框?

4

2 回答 2

2

如果您有网格并且想在搜索工具栏的一个指定输入字段上绑定事件,您可以使用dataEvents相应searchoptions的列colModel(参见此处)。请参阅代码示例的答案

如果您需要将某些事件绑定keyup到网格搜索工具栏的所有输入字段,您可以执行以下操作:

var $grid = $("#list"); // the grid

// create the grid
$grid.jqGrid({
    //... jqGrid options
});

// create the searching toolbar with the line like
$grid.jqGrid('filterToolbar', {defaultSearch: 'cn'});

// get all input fields of the searching toolbar
var $toolbarRow = $grid.closest(".ui-jqgrid-view")
                       .find(".ui-jqgrid-htable .ui-search-toolbar");

// make the binding of all input fields to the event which you need
$toolbarRow.find('input[type="text"]').keyup(function (e) {
    // the code of your event handler
});
于 2012-09-08T11:47:26.160 回答
1

使用jquery live()绑定事件

 $('input[type="text"]').live("click", function(){ .... });
于 2012-09-08T11:23:09.747 回答