簡體   English   中英

即使數據庫中的值為1,復選框也不會顯示為已選中

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM