【问题标题】:Bind a function to jQGrid filtering's textboxes?将函数绑定到 jQGrid 过滤的文本框?
【发布时间】:2012-09-08 11:03:58
【问题描述】:

我用 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 过滤的文本框!

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

【问题讨论】:

    标签: javascript jquery jqgrid textbox keyup


    【解决方案1】:

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

    如果您需要将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
    });
    

    【讨论】:

      【解决方案2】:

      使用jquery live()绑定事件

       $('input[type="text"]').live("click", function(){ .... });
      

      【讨论】:

        猜你喜欢
        • 2014-05-21
        • 1970-01-01
        • 2014-02-19
        • 1970-01-01
        • 2021-10-29
        • 1970-01-01
        • 2011-08-02
        • 2017-04-07
        • 2010-12-02
        相关资源
        最近更新 更多