无法启用/禁用html表行中的输入控件

时间:2018-08-16 13:54:19

标签: javascript html

在选择控件 FeeServiceRequested 的选择更改时,我无法启用/禁用 FeeOtherServiceRequested 输入控件。 只有第一行有效。

我在.net MVC cshtml页面中有此表

<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>

和此javascript函数

function EnableOtherTextbox_Fee(sel) {
    var tableRow = $(sel).closest('tr');
    var FeeOtherServiceRequested = tableRow.find("input[id*='FeeOtherServiceRequested']");
    var inputs = document.getElementById('FeeOtherServiceRequested');

    if (sel.value == "Other (specify)") {
        inputs.disabled = false;
    }
    else {
        inputs.disabled = true; inputs.value = '';
    }
}

enter image description here

1 个答案:

答案 0 :(得分:1)

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

I=6