添加只读/禁用 paremtru 取决于 html 表中的类 tr / td



我有一个问题,是否可以将其设置为将ReadOnly/Disable参数添加到指定类中的DropDownlistFor<'tr class = "TR_two">'<'td class = "TD_two">'

<'tr class = "TR_one">' or <'td class = "TD_one">'将保持不变。

<table>
<tbody>
<tr class="TR_one">
<td class="TD_one">@Html.DropDownListFor(m => m.Model1[nr_rows].PrzyczynaNieobecnosci, new SelectList(Enum.GetValues(typeof(Urlopy))), "  ", new { @class = "selectboxlist" })</td>
</tr>
<tr class="TR_two">
<td class="TD_two">@Html.DropDownListFor(m => m.Model1[nr_rows].PrzyczynaNieobecnosci, new SelectList(Enum.GetValues(typeof(Urlopy))), "  ", new { @class = "selectboxlist" })</td>
</tr>
</tbody>
</table>

你可以利用jQuery来实现这一点。
在页面中添加以下行:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" />

然后,添加以下脚本块:

<script type="text/javascript" language="javascript">
$(document).ready(function() {  
$("td.TD_one").find(".selectboxlist").prop('disabled', 'disabled');
});  
</script> 

上面的脚本选择带有"class = TD_one"的td元素。然后找到具有"class = selectboxlist"的子元素,并设置其"disabled"属性。

最新更新