将表行传递给JS文件

时间:2012-01-28 22:28:14

标签: jquery repeater onchange

我试图不仅使用此传递下拉列表ID,而且我还试图传递该行。

<asp:DropDownList ID="dropdownPhase" _clientId="comboboxPhase" runat="server" Font-Size="xx-small" onchange="SummaryHelper.onPhaseChange(this,this.tr);" />

这是我的JS文件中的Javascript

onPhaseChange: function(dropdown, row) {
    var combobox = $(dropdown);
    var table = combobox.parents("table").eq(0);
    comboboxWorkUnit = row.find("select.workUnit");

    if (combobox.data('oldValue') || !combobox.find("option[value='']").length) {
        comboboxWorkUnit.hide();
    }

},

当我按照它的方式运行时,我收到此错误:

  

Microsoft JScript运行时错误:'undefined'为null或不是对象

1 个答案:

答案 0 :(得分:1)

this.tr没什么。我很想知道你在哪里。

如果你想传递这行,你需要像在函数中一样获取行。

onchange="SummaryHelper.onPhaseChange(this,$(this).closest('tr'));"

这会传递一个带有该行的jQuery对象,因为你在函数中使用它就像一个jQuery对象。


但是你也可以在这个功能中做到这一点。

onPhaseChange: function(dropdown) {
    var combobox = $(dropdown);
    var row = combobox.closest('tr');
    var table = combobox.parents("table").eq(0);
    comboboxWorkUnit = row.find("select.workUnit");

    if (combobox.data('oldValue') || !combobox.find("option[value='']").length) {
        comboboxWorkUnit.hide();
    }

},