Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 选中复选框中的触发器函数,不使用.change()_Javascript_Jquery_Html_Checkbox - Fatal编程技术网

Javascript 选中复选框中的触发器函数,不使用.change()

Javascript 选中复选框中的触发器函数,不使用.change(),javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我有一个动态加载的表,其中每行都有一个复选框选项,分配的#id为1、2或3。我需要创建一个函数,该函数将显示与选中复选框的#id对应的隐藏div。我目前正在使用.change()来触发函数,但在取消选中一个框时会显示隐藏的div,这是我不希望发生的。是否有另一种方法可以触发此函数,使其仅在“已选中”而不是“未选中”时运行。见下面的代码: <tr> <td > <input id="1" class="link_contact" type="chec

我有一个动态加载的表,其中每行都有一个复选框选项,分配的#id为1、2或3。我需要创建一个函数,该函数将显示与选中复选框的#id对应的隐藏div。我目前正在使用.change()来触发函数,但在取消选中一个框时会显示隐藏的div,这是我不希望发生的。是否有另一种方法可以触发此函数,使其仅在“已选中”而不是“未选中”时运行。见下面的代码:

<tr>
   <td >
      <input id="1" class="link_contact" type="checkbox"/>
   </td>
</tr>
<tr>
   <td >
      <input id="2" class="link_contact" type="checkbox"/>
   </td>
</tr>
<tr>
   <td >
      <input id="3" class="link_contact" type="checkbox"/>
   </td>
</tr>

<div class="1" style="display:none;"> Some Hidden Text</div>
<div class="2" style="display:none;"> Some Hidden Text</div>
<div class="3" style="display:none;"> Some Hidden Text</div>

<script>
$(document).ready(function () {
    $(".link_contact").change(function () {
        $("." + $(this).attr('id')).fadeIn(800);
        $("." + $(this).attr('id')).delay(7000).fadeOut(800);
    });
});
</script>

一些隐藏的文本
一些隐藏的文本
一些隐藏的文本
$(文档).ready(函数(){
$(“.link\u contact”).change(函数(){
$(“+$(this.attr('id')).fadeIn(800);
$(“+$(this).attr('id')).delay(7000).fadeOut(800);
});
});
谢谢,
标记您需要使用的
:在函数
is()中选中选择器


$(文档).ready(函数(){
$(“.link\u contact”).change(函数(){
如果($(this).is(“:checked”)){
$(“+$(this.attr('id')).fadeIn(800);
$(“+$(this).attr('id')).delay(7000).fadeOut(800);
$('.dialog_warning')。淡出(800);
}
});
});

选中此项您需要使用
:在函数
is()中选中选择器


$(文档).ready(函数(){
$(“.link\u contact”).change(函数(){
如果($(this).is(“:checked”)){
$(“+$(this.attr('id')).fadeIn(800);
$(“+$(this).attr('id')).delay(7000).fadeOut(800);
$('.dialog_warning')。淡出(800);
}
});
});
检查html标记中是否缺少结尾引号(在样式属性之后)

<div class="3" style="display:none;> Some Hidden Text</div>
html标记中缺少结尾引号(在样式属性之后)

<div class="3" style="display:none;> Some Hidden Text</div>

仅当选中复选框时才执行操作

$(document).ready(function () {
    $(".link_contact").change(function () {
        if (this.checked) {
            $("." + this.id).stop(true, true).fadeIn(800).delay(7000).fadeOut(800);
            $('.dialog_warning').fadeOut(800);
        }
    });
});

演示:

仅当选中复选框时才执行操作

$(document).ready(function () {
    $(".link_contact").change(function () {
        if (this.checked) {
            $("." + this.id).stop(true, true).fadeIn(800).delay(7000).fadeOut(800);
            $('.dialog_warning').fadeOut(800);
        }
    });
});

演示:

谢谢,但那只是一个打字错误。不是我要找的。这个缺失的报价导致了错误;)谢谢,但那只是个打字错误。不是我要找的。缺少的这句话会导致错误;)非常感谢。所有人都尽快给你答案!非常感谢。所有人都尽快给你答案!