首页 > 解决方案 > jQuery combogrid 在选择一行时识别输入框

问题描述

我正在使用 combogrid https://github.com/powderblue/jquery-combogrid在键入时显示建议。

$(".stresses").combogrid({
        url: '/index/stresssearch',
        debug: true,
        colModel: [{'columnName': 'id', 'hidden': true, 'width': '1', 'label': 'id'},{'columnName': 'name', 'width': '39', 'label': 'Name'}],
        select: function (event, ui) {
            $(this).val(ui.item.email);
            return false;
        },

    });

在上面关于选择一行的代码中,我需要将该值分配给输入框。输入框是使用 jQuery 动态生成的。如何识别select函数内的输入框?$(this).val()不管用。

标签: javascriptjquery

解决方案


我通过添加 jQueryon函数解决了它。

$('body').on('focus', '.dynstresses', function () { 
    $(this).combogrid({
        url: '/index/stresssearch',
        debug: true,
        colModel: [{'columnName': 'id', 'hidden': true, 'width': '1', 'label': 'id'},{'columnName': 'name', 'width': '39', 'label': 'Name'}],
        select: function (event, ui) {
            $(event.target).val(ui.item.name);
            return false;
        },

    });
    });

推荐阅读