[英]Checkbox is not showing checked even though the value is 1 from the database
I have a checkbox(As a cloumn to check if the user is active or not) on a kendo Grid Update Window.It is always shown unchecked even though its value is 1(which means User is active).If i check when i debug the VAlue is true if the user is Active but the checkbox is not checked. 我在kendo Grid Update Window上有一个复选框(作为检查用户是否处于活动状态的克隆)。即使其值为1(这意味着用户处于活动状态),它始终显示为未选中状态。如果我在调试时进行检查如果用户为“活动”但未选中该复选框,则VAlue为true。 Can anyone help me with the jquery syntax for this. 谁能帮我这个的jQuery语法。
<td>
<div>
<label for="Active">Active</label>
</div>
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox" />
</div>
</td>
HTML (When i run the code) for one field when its value is 1(Active): 当它的值为1(有效)时,一个字段的HTML(当我运行代码时):
<span>
<input id="Z_ACTIVE" type="checkbox" value="true">
</span>
尝试
<input id="Z_ACTIVE" type="checkbox" checked/>
Give below a try: 请在下面尝试:
<div class="checker" >
<input id="Z_ACTIVE" type="checkbox"
<% if(DBValue=="1") { %>
"checked" <% } %>
/>
</div>
Since you have tagged your question with asp.net
, why aren't you using the Controls provided? 既然您已经用asp.net
标记了问题,为什么不使用提供的控件?
In the .aspx page 在.aspx页中
<asp:CheckBox ID="Z_ACTIVE" runat="server" />
And then in code behind 然后在后面的代码中
if (yourDBvalue == 1)
{
Z_ACTIVE.Checked = true;
}
you write value is 1 from the database
, but that does not magically set a random checkbox to checked if you don't tell it to. 您value is 1 from the database
写入的value is 1 from the database
,但这并不能神奇地设置一个随机复选框以检查是否不告诉您。
The below Code worked for me 下面的代码对我有用
if (Active == "true") {
$("#Active").find('#Active input').attr('checked', 'checked');
}
else {
$("#Active").find("SPAN:first-child").removeClass("checked");
}
In the jQuery, you can have the below line. 在jQuery中,您可以使用以下行。
$("#Z-ACTIVE").attr("checked", true); $(“#Z-ACTIVE”)。attr(“ checked”,true);
Insert your condition above this line to have the database value checked. 在此行上方插入您的条件以检查数据库值。
In order to check a checkbox in HTML - 为了检查HTML中的复选框-
should work as mentioned in the above answers. 应该按照上述答案中所述工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.