[英]Checkbox is not showing checked even though the value is 1 from the database
我在kendo Grid Update Window上有一个复选框(作为检查用户是否处于活动状态的克隆)。即使其值为1(这意味着用户处于活动状态),它始终显示为未选中状态。如果我在调试时进行检查如果用户为“活动”但未选中该复选框,则VAlue为true。 谁能帮我这个的jQuery语法。
<td>
<div>
<label for="Active">Active</label>
</div>
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox" />
</div>
</td>
当它的值为1(有效)时,一个字段的HTML(当我运行代码时):
<span>
<input id="Z_ACTIVE" type="checkbox" value="true">
</span>
尝试
<input id="Z_ACTIVE" type="checkbox" checked/>
请在下面尝试:
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox"
<% if(DBValue=="1") { %>
"checked" <% } %>
/>
</div>
既然您已经用asp.net
标记了问题,为什么不使用提供的控件?
在.aspx页中
<asp:CheckBox ID="Z_ACTIVE" runat="server" />
然后在后面的代码中
if (yourDBvalue == 1)
{
Z_ACTIVE.Checked = true;
}
您value is 1 from the database
写入的value is 1 from the database
,但这并不能神奇地设置一个随机复选框以检查是否不告诉您。
下面的代码对我有用
if (Active == "true") {
$("#Active").find('#Active input').attr('checked', 'checked');
}
else {
$("#Active").find("SPAN:first-child").removeClass("checked");
}
在jQuery中,您可以使用以下行。
$(“#Z-ACTIVE”)。attr(“ checked”,true);
在此行上方插入您的条件以检查数据库值。
为了检查HTML中的复选框-
应该按照上述答案中所述工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.