测试成功
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head><body><script>var img1,img2,i=0;
img1=new Image();
img1.src="http://zi.csdn.net/comm_button.gif";
img2=new Image();
img2.src="http://zi.csdn.net/csdn-ppbutton_120.gif";
function changeimg(){
myimg.src=eval("img"+(i+1)).src;
i=1-i;
t=setTimeout("changeimg()",500);
}
//window.onload=function(){//changeimg()}
str="http://www.it315.org/get.jsp?user=zxx&pass=123";
str=str.replace(/(.*)\?([\w]+)=([\w]+)&([\w]+)=([\w]+)/,"$2,$3,$4,$5");
alert(str);
script=document.createElement("script")
script.src="http://www.05it.net/float.js";
function show(){
confrim.style.display="block"
disabled.style.height=document.body.offsetHeight
disabled.style.width=document.body.offsetWidth-16
disabled.style.display="block"
}
function hide(){
confrim.style.display="none"
disabled.style.display="none"
}
</script>
<img id=myimg src="http://zi.csdn.net/csdn-ppbutton_120.gif" onclick="show()">
<a href="">asd</a>
<div id=confrim style="position:absolute;margin-top:20%;width:200;height:80;border:1px solid #666;background:#EEE;z-index:1001;display:none">
确认删除<br>
<input type=button value=确认 onclick=hide()>
</div>
<div id=disabled style="position:absolute;top:0;left:0;width:1000;height:1000;z-index:1000;background:#eee;;filter:Alpha(Opacity=50);display:none"></div>
</body></html><!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>
function check(fm){
var r=fm.all["tid"];
var count=0;
for(var i=0;i<r.length;i++){
  if(fm.tid[i].checked)
    count++;
}
if (count==0){
  alert("请选择一个任务!");
  return false;
}else
   return true;}
</script>
</head><body>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="6" class="line"><p class="样式1">跟踪任务:</p>
          <p>&nbsp;</p></td>
      </tr>
  <form action="showtask.do?ctr2=2"  name="fm"  onsubmit="alert(1);return check(fm);return false">
   
      <tr bgcolor="#990000">
        <td width="19%" height="22" class="line"><span class="样式10">任务名称</span></td>
        <td width="16%" class="line"><span class="样式10">实施人</span></td>
        <td width="19%" class="line"><span class="样式10">开始时间</span></td>
        <td width="19%" class="line"><span class="样式10">结束时间</span></td>
        <td width="15%" class="line"><span class="样式10">状态</span></td>
        <td width="12%" class="line">&nbsp;</td>
      </tr>
 
      <tr bgcolor="#CCCCCC">
         <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line"><div align="center">
        <input type="radio" name="tid" value="1">
        </td>
      </tr>
      <tr bgcolor="#CCCCCC">
         <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line">xx</td>
        <td height="22" class="line"><div align="center">
        <input type="radio" name="tid" value="2">
        </td>
      </tr>
      <tr>
        <td height="22" colspan="6" class="line"><div align="right">
                  
          <input type="submit" name="Submit" value="详细信息">
        </div></td>
      </tr>
  </form>
    </table>
</body>
</html>
将判断写在form的onsubmit内,并且你的方法内部还有错误。

解决方案 »

  1.   

    你要判断是否是单个还是多个。
    if(obj.length)
    //多个
    else
    //单个
      

  2.   

    把下面的函数改成这样function check(fm){
    var r=document.getElementsByName("tid");
    var count=0;
    for(var i=0;i<r.length;i++){
      if(r[i].checked)
        count++;
    }
    if (count==0){
      alert("请选择一个任务!");
      return false;
    }else
       return true;}
    </script>
      

  3.   

    function check(fm){
    //var r=fm.all["id"];
    var count=0;
    if(typeof(fm.tid.length)!="undefined")  //加上这个判断
    {
    for(var i=0;i<fm.tid.length;i++){
    if(fm.tid[i].checked)
    count++;
    }
    }else
    {
    if(fm.tid.checked)
    count++;

    }
    if (count==0){
    alert("请选择一个任务!");
    return false;
    }else
    return true;
    }原因是:如果只有一个radio或checkbox不能用数组来表示,fm.tid[0]类型是undefined,应该用fm.tid才对
      

  4.   

    感谢楼上几位实际上判断是否一个多个用  type属性就可以了。。一个的就是“radio“,楼上的方法也对~~