English 中文(简体)
如果检查结果未经检查
原标题:if any checked check else uncheck

can someone help me with some traversing and some logic here please. the logic is this:

  1. if any checkbox in column3 is checked then check the first column checkbox.
  2. if none in column 3 is selected, uncheck checkbox in column1
  3. 如果第1栏的检查箱没有检查,那么第3栏中的所有检查箱就没有检查。

    <table>
        <tr>
           <td><input class="isSelected" type="checkbox" /></td>
           <td>row1col2</td>
           <td><input class="actionItem" type="checkbox" /><input class="actionItem" type="checkbox" /></td>
        </tr>
        <tr>
            <td><input class="isSelected" type="checkbox" /></td>
            <td>row2col2</td>
            <td><input class="actionItem" type="checkbox" /><input class="actionItem" type="checkbox" /></td>
        </tr>
        <tr>
            <td><input class="isSelected" type="checkbox" /></td>
            <td>row3col2</td>
            <td><input class="actionItem" type="checkbox" /><input class="actionItem" type="checkbox" /></td>
        </tr>
    </table>
    

最佳回答

http://jsfiddle.net/mblase75/NDh2g/“rel=“nofollow”http://jsfiddle.net/mblase75/NDh2g/

$( table tr ).find( input:checkbox:first ).change(function() {
    var $this = $(this);
    $this.closest( tr ).find( input:checkbox ).prop( checked , $this.prop( checked ));
});

$( table tr ).find( input:checkbox:not(":first") ).change(function() {
    var tmp = true;
    var $this = $(this);
    $this.closest( tr ).find( input:checkbox:not(":first") ).each(function() {
        tmp &= $(this).prop( checked );
    });
    $this.closest( tr ).find( input:checkbox:first ).prop( checked ,tmp);
});
问题回答

我也假设,在第一个col子的检查箱没有受到检查时,你也想对第3栏的所有物项进行核对。

Try this:

$("input.actionItem").change(function() {
    var $t = $(this); 
    var checked = ($t.closest("td").find("input.actionItem:checked").length > 0);
    $t.closest("tr").find("input.isSelected").prop("checked", checked);
});

$("input.isSelected").change(function() {
    var $t = $(this); 
    var status = $t.prop("checked");
    $t.closest("tr").find("input.actionItem").prop("checked", status);   
});

请注意,这用类别名称区别对待不同的核对箱类型,而不是它们重新使用的栏目。

为明确瞄准栏目,你可以做如下事情:。 http://jsfiddle.net/NvCDp/

$("tr > td:nth-child(3)").find("input.actionItem").change(function() {
    var $t = $(this);
    var checked = $t.prop("checked") ? true : ($t.siblings("input:checked").length > 0);
    $("td:first", $t.closest("tr")).find("input")
            .prop("checked", checked);
});

$("tr > td:first-child").find("input.isSelected").change(function() {
    var $t = $(this);
    var checked = $t.prop("checked");
    $t.closest("tr").find("td:nth-child(3) input.actionItem")
            .prop("checked", checked);
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签