在下面的脚本中,我正在尝试使用类“cb-checkURL”评估所有复选框项目,如果选中,我想通过 jQuery show() 将最近的“.wl-options”div 设置为 display:block。
但是,我错过了一些东西, .each 没有做这项工作。有任何想法吗?
jQuery(document).ready(function(){
jQuery.each( ".cb-checkURL", function() {
if(jQuery(this).attr("checked")){
jQuery(this).parent().next(".wl-options").show();
}
else
{
jQuery(this).parent().next(".wl-options").hide();
}
});
jQuery(".cb-checkURL").click(
function(){
jQuery(this).parent().next(".wl-options").toggle();
});
})';
HTML 源
<label class="wl-active">
<input class="cb-checkURL" type="checkbox" name="wl[item-2][location][is_url]" checked="checked"> URL
</label>
<div class="wl-options" style="clear:both;max-width:400px;display:none">
<div class="cb-urls">
<label title="Enter one url slug per line" for="wl[item-2][url][urls]"></label>
<textarea name="wl[item-2][url][urls]" id="wl[item-2][url][urls]"></textarea>
</div>
</div>