2015-03-03 110 views
0

后,我有一个嵌套的手风琴,像这样:触发事件.slideDown

<script> 
$(document).ready(function(){ 

    var parentDivs = $('#standard div'), 
     childDivs1 = $('#standard h4').siblings('div'); 
     childDivs2 = $('#standard h5').siblings('div'); 

    $('#standard h3').click(function() { 
     parentDivs.slideUp(); 
     if ($(this).next().is(':hidden')) { 
      $(this).next().slideDown({easing:'easeOutQuad', duration:1000}); 
     } else { 
      $(this).next().slideUp({easing:'easeOutQuad', duration:1000}); 
     } 
    }); 

    $('#standard h4').click(function() { 
     childDivs1.slideUp(); 
     if ($(this).next().is(':hidden')) { 
      $(this).next().slideDown({easing:'easeOutQuad', duration:1000}); 
     } else { 
      $(this).next().slideUp({easing:'easeOutQuad', duration:1000}); 
     } 
    }); 

    $('#standard h5').click(function() { 
     childDivs2.slideUp(); 
     if ($(this).next().is(':hidden')) { 
      $(this).next().slideDown({easing:'easeOutQuad', duration:1000}); 
     } else { 
      $(this).next().slideUp({easing:'easeOutQuad', duration:1000}); 
     } 
    }); 

}); 
</script> 

内容div的包含单选按钮:

<p class="radioBtn"> 
<label for="input-1-1">Yes </label> <input id="input-1-1" name="clause" data-completed-id="1" value="1" type="radio" checked/> 
</p> 
<p class="radioBtn"> 
<label for="input-1-2">No </label> <input id="input-1-2" name="clause" data-completed-id="1" value="0" type="radio" /> 
</p> 

我所要做的就是让他们开枪更改使用下面的代码:

$('input:radio[name=clause]').change(function() { 
alert("Test!"); 
}); 

但是,当我改变单选按钮没有任何反应。

+0

您的收音机代码在此正常工作http://jsfiddle.net/xz6f76pr/ – charlietfl 2015-03-03 01:36:06

+0

您的收音机按钮更改提醒“测试!”它的工作正常! – iamsuman 2015-03-03 01:37:37

+0

你有没有在$(document).ready中更改脚本???如果没有,你的事件没有附加到jquery – daremachine 2015-03-03 01:49:19

回答

0

试试这个
$("input[name='clause']").on('change',function() { alert("Test!"); });

+0

已经被证明可以工作的'change()'只是'on'('change')'的一个快捷方法'..没有真正的原因会改善任何东西 – charlietfl 2015-03-03 01:46:44

+0

也行不通。 – 2015-03-03 03:37:03

0

您的代码就可以了。尝试把它放在一个文件事件,像这样...

$(document).ready(function() { 
    $('input:radio[name=clause]').change(function() { 
     alert("Test!"); 
    }); 
}) 
0

好吧,我已经解决了。我忘了我正在使用jQuery插件iCheck,它有自己的一组回调。

对不起浪费大家的时间。