单击删除按钮后,将取消选中该复选框

时间:2015-09-17 04:36:30

标签: javascript jquery checkbox

我试图在有人确认删除项目后取消选中我的复选框。想知道我是怎么做的吗?希望有人能帮助我。

这是我的代码:

JS:

double latHomeTmp = (pi/180)*(latHome);
double latDestTmp = (pi/180)*(latDest);
double a = sin(differenceLat/2.) * sin(differenceLat/2.) + 
           cos(latHomeTmp) * cos(latDestTmp) * 
           sin(differenceLon/2.) * sin(differenceLon/2.);

HTML:

$(".rem-btn").click(function(){
        var remConf = confirm("Are you sure you want to remove these items from your shopping list?");
        if (remConf == true) {
            $(".check-list input:checked").not('#select-all').parent().remove();
        };
});

2 个答案:

答案 0 :(得分:2)

使用prop取消选中该复选框:$("#select-all").prop("checked",false);您可以定义所需的任何选择器。



$(".rem-btn").click(function(){
        var remConf = confirm("Are you sure you want to remove these items from your shopping list?");
        if (remConf == true) {
            $(".check-list input:checked").not('#select-all').parent().remove();
          $("#select-all").prop("checked",false);
        };
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<section class="shop-list">
            <div class="add-item">
                <input id="item-add" type='text' placeholder="Enter item to shopping list..." name="itemAdd"></input>
                <button class="add-btn">Add Item</button>
            </div>
            <div class="item-list">
                <h2>Shopping List</h2>              
                <ul class="check-list">
                    <li><input type="checkbox" id="select-all"/>Select All</li>
                </ul>
            </div>  
            <div class="removal">
                <button class="rem-btn">Remove Selected</button>
            </div>
        </section>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

default 10.7.227.109 0.0.0.0 UG 0 0 0 eth1

FIDDLE

选中$(".rem-btn").click(function () { var remConf = confirm("Are you sure you want to remove these items from your shopping list?"); if (remConf == true) { console.log('qeqw'); $(".check-list input:checked").attr('checked',false); }; }); 并将其设置为false或使用attr