簡體   English   中英

使用JQuery獲取復選框選中狀態

[英]Get checkbox checked state using JQuery

我被分配來獲取復選框的布爾值。

我找不到一種方法來獲取復選框的布爾值。 例如:true,false。

有沒有辦法做到這一點?

鏈接: https//jsfiddle.net/hongyang1033/ek30dgt9/5/

    <body>

    <div >

    <table border=1px>

  <thead>
    <tr>
        <th colspan="5">Description</th>
        <th>Comment</th>
        <th>User</th>
        <th>Feedback</th>
        <th>Status</th>
    </tr>
    </thead>
        <tbody style="border-top : 1px solid black" id = "1">
    <tr>
        <td class="partition"><label class="label">Title:</label><label class="label ">A</label></td>
        <td class="sip" style="border-left:none"><label class="label">Author:</label><label class="label">James</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="bookstore">BookStore</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="ebook">Ebook</label></td>
        <td rowspan="4"><input type="checkbox"><label class="label" style="padding-left:0px" id="library">Library</label></td>
        <td rowspan="4"><textarea maxlength="180" class="animated" id="usercomment" name="comment" style="overflow: hidden; word-wrap: break-word; resize: horizontal;  height: 80px; width:280px;">The book is ..........</textarea></td>
        <td rowspan="4" align="center">Adam<br><button class="label label-primary" id="submit">Submit</button></td>
        <td rowspan="4" align="center">Feedback Goes Here<br></td>
            <td rowspan="4" align="center"><br>No Feedback Yet</td>
    </tr>
    <tr>
        <td colspan="2" class="def"><label class="label">Genre:</label><label class="label">Fiction</label></td>
    </tr>
    <tr>
        <td colspan="2" class="path"><label class="label label-primary" style="margin-left:5px">BookURL</label><label class="label label-primary " style="margin-left:40px">DownloadLink</label></td>
    </tr>
    <tr>
        <td colspan="2" class="path"><a style="display:none">www.ddd.com/bookurl</a></td>
    </tr>
</tbody>

jQuery查詢

$("#submit").click(function() {
var $row = $(this).closest("tbody");   
var $text = $row.document.getElementById("#emulation").checked(); // 
alert($text);
});

由於id是唯一的,因此您可以直接獲取它。 使用is()函數檢查屬性。

從更新

var $text = $row.document.getElementById("#emulation").checked() ;

var $text = $("#emulation").is(":checked"); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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