Javascript 无法在html表格行中启用/禁用输入控件

Javascript 无法在html表格行中启用/禁用输入控件,javascript,html,Javascript,Html,我无法在选择控件的选择更改时启用/禁用FeeOtherServiceRequested输入控件。 只有第一排在工作 我在.NETMVCSHTML页面中有这个表 <tbody> @foreach (DataRow row in Model.Tables["PM_Fee"].Rows) { <tr>

我无法在选择控件的选择更改时启用/禁用FeeOtherServiceRequested输入控件。 只有第一排在工作

我在.NETMVCSHTML页面中有这个表

<tbody>
                    @foreach (DataRow row in Model.Tables["PM_Fee"].Rows)
                    {
                        <tr>
                            <td>
                                <div class="editDelInputFee FeeServiceRequestedText">
                                    @row["FeeDescription"]
                                </div>
                                <div class="saveCanInputFee FeeServiceRequestedSelectFee" style="display:none">
                                    <select class="form-control form-control-sm " style="font-size:8pt;" id="FeeServiceRequested" onchange="EnableOtherTextbox_Fee(this);">
                                        @foreach (DataRow row0 in Model.Tables["PM_Fee_ServiceRequested"].Rows)
                                        {
                                            <option value="@row0["ServiceRequested"]">@row0["ServiceRequested"]</option>
                                        }
                                    </select>
                                </div>
                            </td>
                            <td>
                                <div class="editDelInputFee FeeOtherServiceRequestedText">
                                    @row["FeeOtherDescription"]
                                </div>
                                <div class="saveCanInputFee FeeOtherServiceRequestedInputFee" style="display:none">
                                    <input type="text" class="form-control form-control-sm " style="font-size:8pt;" id="FeeOtherServiceRequested">
                                </div>
                            </td>
                             </tr>
                    }  
    </tbody>

好的,我这样做是为了解决这个问题。从输入控件中删除ID并修改此方法

function EnableOtherTextbox_Fee(sel) {
    var tableRow = $(sel).closest('tr'); 
    var inputs = tableRow.find('.FeeOtherServiceRequestedInputFee input');      
    if (sel.value == "Other (specify)") {
        inputs.prop("disabled", false); 
    }
    else {
        inputs.prop("disabled", true); inputs.val('');
    }
}

在一个网页上不能有相同的id。由于您使用forloop生成taberows并为每一行定义相同的id,因此它只会选择第一个1。。我应该使用名称而不是ID吗?@sak您可以使用动态ID,比如在ID后面附加一些唯一的内容,并在enableOtherTextbox\u函数中引用它
function EnableOtherTextbox_Fee(sel) {
    var tableRow = $(sel).closest('tr'); 
    var inputs = tableRow.find('.FeeOtherServiceRequestedInputFee input');      
    if (sel.value == "Other (specify)") {
        inputs.prop("disabled", false); 
    }
    else {
        inputs.prop("disabled", true); inputs.val('');
    }
}