我正在尝试使用jQuery查看表单,并为每个复选框“if checked”然后显示包含textarea的div。
复选框ID'checkbiox_foo'的每个div都是id'checkse_foo_reasons'
我是jquery的总菜鸟,所以我已经走到了这一步,但我无法选择div来隐藏或显示它。
$(document).ready(function() {
$('#storySelection input').each(function(){
if($(this).is(':checked') ){
alert($('#'+this.id+'_reasons'));
}
});
});
感谢任何帮助。
干杯,
保
答案 0 :(得分:0)
如果没有看到您的HTML,我无法确定,但您可能想要这样的内容:
$(function () {
$('#storySelection input').click(function () {
var $this = $(this);
if ($this.is(':checked')) {
$this.next('div').show();
} else {
$this.next('div').hide();
}
})
});
答案 1 :(得分:0)