根据控制器的 bool 参数禁用 HTML 输入的属性 - ASP.NET MVC
Disable attribute for HTML input based on a bool parameter from Controller - ASP.NET MVC
有没有办法根据布尔变量使输入可见?
<input type="button" value="Smth" onclick="...">
我正在为此目的寻找一个 HTML 帮手,但到目前为止还没有成功。
试试这个
@if ( your bool condition)
{
<input type="button" value="Smth" onclick="..."> //visible
}
else
{
<input type="button" class="d-none" value="Smth" onclick="..."> //none-visible
//or
<input type="button" hidden value="Smth" onclick="...">
}
您可以通过使用 ternary conditional
运算符将 input
字段设置为禁用来达到所需的结果:
<input type="button" value="Smth" onclick="..." @(myBoolCondition == "true" ? "disabled='disabled'" : "") >
其中 myBoolCondition
是保存条件结果的变量。
有没有办法根据布尔变量使输入可见?
<input type="button" value="Smth" onclick="...">
我正在为此目的寻找一个 HTML 帮手,但到目前为止还没有成功。
试试这个
@if ( your bool condition)
{
<input type="button" value="Smth" onclick="..."> //visible
}
else
{
<input type="button" class="d-none" value="Smth" onclick="..."> //none-visible
//or
<input type="button" hidden value="Smth" onclick="...">
}
您可以通过使用 ternary conditional
运算符将 input
字段设置为禁用来达到所需的结果:
<input type="button" value="Smth" onclick="..." @(myBoolCondition == "true" ? "disabled='disabled'" : "") >
其中 myBoolCondition
是保存条件结果的变量。