如何判断CheckBox选中/未选中? 用JavaScript,如何判断CheckBox选中/未选中?具体代码怎么写?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 checked属性true和false来判断 写代码不好吗?思路我也知道,具体写起来就是不管用,我想要的是正确的写法。凡是人都知道checked属性 <html><head><meta http-equiv="Content-Language" content="zh-cn"><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title><script> function show() { var ch1=document.getElementById("ch1"); alert(ch1.checked); }</script></head><body><form> <input id="ch1" type="checkbox" name="bike" />I have a bike<br /> <input type="checkbox" name="car" />I have a car</form><input type="button" value="CLICK ME" onclick="show()"/></body></html> 参考...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>TEST</title></head><style type="text/css">*{font-family:verdana; font-size:12px;}</style><script type="text/javascript">function $(id){return "string" == typeof(id) ? document.getElementById(id) : id ;}function trim(str){ return str.replace(/^\s|\s$/g,"");}function check(){var o1=$("chkbox1");var o2=$("chkbox2");var msg='';if(o1.checked) msg = 'box1 选中, 值 = '+ o1.value+'\n';elsemsg = 'box1 没选中\n';if(o2.checked) msg += 'box2 选中, 值 = '+ o2.value+'\n';elsemsg += 'box2 没选中\n';alert(msg);}</script><body>box1:<input name="chkbox1" id="chkbox" type="checkbox" value="OK">OKbox2:<input name="chkbox2" id="chkbox" type="checkbox" value="NO">NO<br><a href="javascript:check();">check </a></body></html> jquery的 供楼主学习!<html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script></head><body> <input type="checkbox" name="publish" value="人民教育出版社">人民教育出版社 <input type="checkbox" name="publish" value="北京师范大学出版社">北京师范大学出版社 <input type="checkbox" name="publish" value=""></body></html><script> $(function () { //跟多选框添加点击事件 $("input[type='checkbox']").bind("click", function () { //如果选中 if (this.checked == true) { //弹出值 alert(this.value); } }); });</script> <!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=utf-8" /><title>无标题文档</title></head><body><script> function abc(){ var c=window.document.forms.item(0).childNodes.item(0).checked; alert(c) } function def(){ var c=window.document.forms.item(0).childNodes.item(1).checked; alert(!c) }</script><form name="abcd" ><input type="checkbox" name="a" checked="checked" onclick="abc()" /><input type="checkbox" name="b" onclick="def()"/><input type="button" value="234" onclick="abc()" /></form></body></html> <input type="checkbox" name="love" onclick="c(this)">x <input type="checkbox" name="love" onclick="c(this)">y <input type="checkbox" name="love" onclick="c(this)">z <input type="checkbox" name="love" onclick="c(this)">a <input type="checkbox" name="love" onclick="c(this)">b <input type="checkbox" name="love" onclick="c(this)">c <input type="checkbox" name="love" onclick="c(this)">d <script> function c(o){ if(o.checked==true){ o.disabled = true; } } </script> strbScript.Append("document.getElementById('").Append(Me.txtBankKBN.ClientID).AppendLine("').style.cssText = StyleBankKBNYellow;")这一句是正确的。strbScript.AppendLine("if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true){}")用相同的写法,想写在If判断句中就不管用了,请问错在哪里?该怎么改? 正解:strbScript.AppendLine("if(document.getElementById('"&Me.rdbSiharaiOnly.ClientID&"').checked == true){}") 你用jQuery阿,这个功能很好实现的 做一个登入界面点击登入按钮没用,不跳转,eclipse也不报错,用ie9的开饭这工具说SCRIPT5009: “submit”未定义 extjs获取元素的问题 如何在js中嵌入代码计算整个网页完全载入耗费的时间? 如何用js在iframe中打开网页 javascript 的问题 新手问题:EXT中分页显示 prototypejs each方法 调试好的javascript程序,为何在有些浏览器上不执行? 为什么会出现这个错误,只能填加一个不能删除 请问一个css样式的问题,大家进来看看 求一段代码的解释 如何自动跳到下一个输入框?(不是按回车,有难度)
写代码不好吗?
思路我也知道,具体写起来就是不管用,我想要的是正确的写法。
凡是人都知道checked属性
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script>
function show()
{
var ch1=document.getElementById("ch1");
alert(ch1.checked);
}
</script>
</head>
<body>
<form>
<input id="ch1" type="checkbox" name="bike" />I have a bike<br />
<input type="checkbox" name="car" />I have a car
</form>
<input type="button" value="CLICK ME" onclick="show()"/>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>TEST</title>
</head>
<style type="text/css">
*{font-family:verdana; font-size:12px;}
</style>
<script type="text/javascript">
function $(id){
return "string" == typeof(id) ? document.getElementById(id) : id ;
}function trim(str){
return str.replace(/^\s|\s$/g,"");
}function check(){
var o1=$("chkbox1");
var o2=$("chkbox2");
var msg='';
if(o1.checked)
msg = 'box1 选中, 值 = '+ o1.value+'\n';
else
msg = 'box1 没选中\n';if(o2.checked)
msg += 'box2 选中, 值 = '+ o2.value+'\n';
else
msg += 'box2 没选中\n';
alert(msg);
}
</script>
<body>
box1:<input name="chkbox1" id="chkbox" type="checkbox" value="OK">OK
box2:<input name="chkbox2" id="chkbox" type="checkbox" value="NO">NO
<br><a href="javascript:check();">check </a>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
</head>
<body>
<input type="checkbox" name="publish" value="人民教育出版社">人民教育出版社
<input type="checkbox" name="publish" value="北京师范大学出版社">北京师范大学出版社
<input type="checkbox" name="publish" value="">
</body>
</html>
<script>
$(function () {
//跟多选框添加点击事件
$("input[type='checkbox']").bind("click", function () {
//如果选中
if (this.checked == true) {
//弹出值
alert(this.value);
}
});
});
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<script>
function abc(){
var c=window.document.forms.item(0).childNodes.item(0).checked;
alert(c)
}
function def(){
var c=window.document.forms.item(0).childNodes.item(1).checked;
alert(!c)
}
</script>
<form name="abcd" >
<input type="checkbox" name="a" checked="checked" onclick="abc()" />
<input type="checkbox" name="b" onclick="def()"/>
<input type="button" value="234" onclick="abc()" />
</form>
</body>
</html>
<input type="checkbox" name="love" onclick="c(this)">x
<input type="checkbox" name="love" onclick="c(this)">y
<input type="checkbox" name="love" onclick="c(this)">z
<input type="checkbox" name="love" onclick="c(this)">a
<input type="checkbox" name="love" onclick="c(this)">b
<input type="checkbox" name="love" onclick="c(this)">c
<input type="checkbox" name="love" onclick="c(this)">d <script>
function c(o){
if(o.checked==true){
o.disabled = true;
}
}
</script>
strbScript.AppendLine("if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true){}")用相同的写法,想写在If判断句中就不管用了,请问错在哪里?
该怎么改?