如何判断RadioButton选中/未选中? 用JavaScript,如何判断RadioButton选中/未选中?具体的代码该怎么写?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 JS里的代码<script language="javascript">function check(){if(document.fr.sex[0].checked==false&&document.fr.sex[1].checked==false){alert("性别必须选择其一!");return false;}}页面<form action="<%=request.getContextPath() %>/EmpServlet?action=add" name="fr" method="post" onsubmit="return check()"><input type="radio" name="sex" value="男" >男<input type="radio" name="sex" value="女" >女</from> 就是检查 checked 属性,自己查手册吧Web 开发常用手册DHTML 参考手册http://download.csdn.net/source/308913JScript 语言参考http://download.csdn.net/source/308916CCS 样式表中文手册http://download.csdn.net/source/304124 <input type="radio" name="love" onclick="c(this)">x <input type="radio" name="love" onclick="c(this)">y <input type="radio" name="love" onclick="c(this)">z <input type="radio" name="love" onclick="c(this)">a <input type="radio" name="love" onclick="c(this)">b <input type="radio" name="love" onclick="c(this)">c <input type="radio" name="love" onclick="c(this)">d <script> function c(o){ if(o.checked==true){ o.disabled = true; } } </script> 你这里边的fr , sex[0] 具体是什么东西? //判断第一个单选按钮的和第二个单选按钮的选择状态,如果都为false,代表都没选中。if(document.fr.sex[0].checked==false&&document.fr.sex[1].checked==false)fr 是form表单id,sex[0]第一个单选按钮。意思就是:id为fr,下面的第一个单选按钮 没错,就是通过checked这个属性来判断的。如查是true就是被选中的,是false就是没被选中的。 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head> <title>Untitled</title> <script> function isChecked(obj){ if(obj.checked==true){ alert("你选种的是" + obj.value); } } </script></head><body><form><input type="radio" name="love" onclick="isChecked(this)" value="a">a<input type="radio" name="love" onclick="isChecked(this)" value="b">b</form></body></html> if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true)这样写为什么不行呢? 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.jframe.js插件用法 请教在动态生成好的table中,有名称项,规格项,如何使相同名称不同规格的数据,价格是一样的。 求一“以星号结尾”javascript正则表达式 js中奇怪的问题return false 也能提交表单 怎么可以加个符号 getAttribute("innerHTML") 的问题 请教在线答题的问题! 在text输入框中,当我输入完数据后,鼠标离开输入框我想触发事件,javascript语句怎么写 对视频的预览问题,高分请教,在线等待!! jQuery 数据修改问题 图片浏览器 用jquery怎么取父节点的兄弟节点?
JS里的代码
<script language="javascript">
function check()
{
if(document.fr.sex[0].checked==false&&document.fr.sex[1].checked==false)
{
alert("性别必须选择其一!");
return false;
}
}
页面
<form action="<%=request.getContextPath() %>/EmpServlet?action=add" name="fr" method="post" onsubmit="return check()">
<input type="radio" name="sex" value="男" >男<input type="radio" name="sex" value="女" >女
</from>
Web 开发常用手册DHTML 参考手册
http://download.csdn.net/source/308913JScript 语言参考
http://download.csdn.net/source/308916CCS 样式表中文手册
http://download.csdn.net/source/304124
<input type="radio" name="love" onclick="c(this)">x
<input type="radio" name="love" onclick="c(this)">y
<input type="radio" name="love" onclick="c(this)">z
<input type="radio" name="love" onclick="c(this)">a
<input type="radio" name="love" onclick="c(this)">b
<input type="radio" name="love" onclick="c(this)">c
<input type="radio" name="love" onclick="c(this)">d <script>
function c(o){
if(o.checked==true){
o.disabled = true;
}
}
</script>
你这里边的fr , sex[0] 具体是什么东西?
if(document.fr.sex[0].checked==false&&document.fr.sex[1].checked==false)
fr 是form表单id,sex[0]第一个单选按钮。意思就是:id为fr,下面的第一个单选按钮
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html>
<head>
<title>Untitled</title>
<script>
function isChecked(obj){
if(obj.checked==true){
alert("你选种的是" + obj.value);
}
}
</script>
</head><body><form>
<input type="radio" name="love" onclick="isChecked(this)" value="a">a
<input type="radio" name="love" onclick="isChecked(this)" value="b">b
</form></body>
</html>
if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true)这样写为什么不行呢?
strbScript.AppendLine("if (document.getElementById('").Append(Me.rdbSiharaiOnly.ClientID).AppendLine("').checked == true){}")用相同的写法,想写在If判断句中就不管用了,请问错在哪里?
该怎么改?