职业IT人-IT人生活圈

 找回密码
 成为会员
搜索
查看: 1280|回复: 0

JavaScript判断Form中的Radio是否有未选中的

[复制链接]
好色之图 发表于 2007-8-12 09:40 | 显示全部楼层 |阅读模式
function getCheckedValue(radioObj) ...{
  if(!radioObj)
    return \"\";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
    if(radioObj.checked)
      return radioObj.value;
    else
      return \"\";
  for(var i = 0; i < radioLength; i++) ...{
    if(radioObj.checked) ...{
      return radioObj.value;
    }
  }
  return \"\";
}
function check()
...{
for(i = 0; i < document.submitform.all.length; i++)...{
if(document.submitform.all(i).tagName == \"INPUT\")...{
  var oitem = document.submitform.all.item(i);
  var sname = oitem.name;
  if(oitem.type.toLowerCase()==\"radio\")...{
   if(getCheckedValue(document.getElementsByName(oitem.name)) == \"\")...{
    oitem.focus();
    window.scrollBy(0, -30);
    alert(\"请认真填写所有题目。\");
    return (false);
   }
  }
}
}
document.submitform.submit();
}
getCheckedValue 获取单选框的值,
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
return \"\";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
  return radioObj.value;
else
  return \"\";
for(var i = 0; i < radioLength; i++) {
if(radioObj.checked) {
  return radioObj.value;
}
}
return \"\";
}
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked

function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj.checked = false;
if(radioObj.value == newValue.toString()) {
  radioObj.checked = true;
}
}
}
check函数,判断所有单选框是否有未选择的,如果有显示提示.
您需要登录后才可以回帖 登录 | 成为会员

本版积分规则

QQ|手机版|小黑屋|网站帮助|职业IT人-IT人生活圈 ( 粤ICP备12053935号-1 )|网站地图
本站文章版权归原发布者及原出处所有。内容为作者个人观点,并不代表本站赞同其观点和对其真实性负责,本站只提供参考并不构成任何投资及应用建议。本站是信息平台,网站上部分文章为转载,并不用于任何商业目的,我们已经尽可能的对作者和来源进行了通告,但是能力有限或疏忽造成漏登,请及时联系我们,我们将根据著作权人的要求立即更正或者删除有关内容。

GMT+8, 2024-5-9 07:19 , Processed in 0.108589 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表