我使用“ iCheck jQuery”来修改复选框的样式。但是,当我添加iCheck脚本时-我的onlick脚架停止工作。为什么会这样呢?
<input id="my_cb" type="checkbox" value="yes_n" onclick="hide_row_metod()"/>
<script>
$(document).ready(function(){
$('#my_cb').iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%' // optional
});
});
</script>
我的剧本:
<script>
function hide_row_metod() {
if(document.getElementById('my_cb').checked){
document.getElementById('row1').style.display = "none";
}else{
document.getElementById('row1').style.display = "inline";
}
}
</script>
iCheck
注册您可以监听的自定义事件。我在jsbin上建立了一个工作示例,主要区别是:
$("#my_cb").on("ifChanged", hide_row_metod);
有两个事件:ifChecked
和ifUnchecked
。如果要捕获对复选框的所有更改,则需要同时收听或仅收听ifChanged
。正如您在中测试的checked
那样,这将有助于切换行hide_row_metod
。
在我的示例中,我使用了block元素div#row1
,因此inline
在选中和取消选中之后,它将呈现不同的()。
另外:您的方法名称中有一个错字(缺少h
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句