http://www.irenezone.com/devarticles/article.jsf?articleId=11918
11918. checkbox复选框,如何让其勾选时触发一个事件,取消勾选时不触发。onclick在勾选和取消勾选都会触发。
参考连接 http://www.irenezone.com/devarticles/article.jsf?articleId=11918
<input type="checkbox" onclick="checkboxOnclick(this)" />
<script>
function checkboxOnclick(checkbox){
if ( checkbox.checked == true){
//Action for checked
}else{
//Action for not checked
}
}
</script>
这个很好实现
onclick
你可以就在onclick里写,判断是被选中了还是没被选中
如果被选中了就执行你要执行的代码
如果没选中就什么都不执行,就可以
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script defer="defer">
function test(){
var $ = document.getElementById;
if($('checkBoxId').checked == true){
alert("选中");
subMit();
}
if($('checkBoxId').checked == false){
alert("未选中");
subMit1();
}
}
function subMit(){
alert("执行选中的函数");
}
function subMit1(){
alert("执行位选中的函数");
}
</script>
</head>
<body>
<input type="checkbox" name="checkbox" id="checkBoxId" value="checkbox" />
选中
<input name="" value="执行" type="button" onclick="test()" />
| 论坛热门帖子: | [lch203] 写得蛮好的linux学习笔记(10-21) [黑马制造] 学习java的30个目标(10-19) [笑傲股林] 做测试半年了,有点迷茫,应该再学些什么提高自己的测试水平和测试能力呢?(10-19) [udp8589] 大家用google的来吱一声? 用百度的~~也来报道下?(10-18) [沂偌掳兆] 本人总结的一些认为C++比较经典的书籍,希望对大家有用(10-18) |
| TAG标签: | 取消 一个 如何 事件 选中 checkbox 执行 onclick function |
注册
个人空间
