简体   繁体   English

复选框切换更改,无需任何用户交互

[英]checkbox toggle change without any user interaction

I call a function in jquery for a checkbox toggle change. 我在jQuery中为复选框切换更改调用了一个函数。 It works as expected. 它按预期工作。 Now I want to change this when the box is checked show some tables else hide. 现在,当框被选中时,我想更改它,显示一些其他表。 But I don't know how to modify my function.. [1] 但是我不知道如何修改我的功能。[1]

How can I modify this ? 我该如何修改呢?

[1] HTML [1] HTML

  <label class="checkbox">                     <input type="checkbox" id="toggleSequence" name="sequence_check" id="sequence_check">

Jquery jQuery的

$("#toggleSequence").change(function(e){
    if($(this).is(":checked")){
        $(this).parent().next().show();

    }else{
        $(this).parent().next().hide();

    }
});

JS Fiddle JS小提琴

$('#toggleSequence').parents('table').next().hide(); // first you need to hide it use can also use css for this

$("#toggleSequence").change(function (e) {
    if ($(this).is(":checked")) {
        alert();
        $(this).parents('table').next().show();

    } else {
        $(this).parents('table').next().hide();

    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM