简体   繁体   English

即使数据库中的值为1,复选框也不会显示为已选中

[英]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.

相关问题 即使未选中也获取复选框值? - Get checkbox value even if not checked? 值不显示,即使它在HTML中 - Value not showing, even though it is in the HTML 角度的-即​​使选中此复选框,此声明字段也始终为false - angular - this declaration field is always false even though the checkbox checked 如何将选中的复选框的值保存到数据库 - How to save the value of the checked checkbox to the database 复选框使用jquery检查值是否在php的数据库中 - checkbox is checked if value is in database in php using jquery 即使最后一行已从数据库中删除,也不要在列表中显示它 - Stop last row from showing in list even though it has been removed from database 始终检查网格单元格中的Jqwidget复选框,即使其来自Json的值为false - Jqwidget checkbox in grid cell is allways checked even if its value coming from Json is false 根据选中的复选框显示数据库的结果 - display result from database based on checked checkbox 如果值匹配,则选中复选框,并在提交时使用复选框值更新数据库 - If value match then checkbox checked and update database with checkbox values on submit 即使未选中复选框,我的javascript语句也不会运行else语句 - My javascript statement won't run its else statement even though checkbox isn't checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM