![](/img/trans.png)
[英]Disable/enable input box type 'number' on tick of checkbox in an HTML table
[英]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.