簡體   English   中英

無法啟用/禁用html表行中的輸入控件

[英]unable to enable/disable the input control in html table row

我無法在選擇控件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 = '';
    }
}

在此處輸入圖片說明

好的,我這樣做是為了解決它。 從輸入控件中刪除了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('');
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM