<form name=f>
<input type=radio name=txt>
<input type=radio name=txt>
<input type=radio name=txt>
<input type=radio name=txt>
<input type=button onclick="test()" vaLUE="TEST">
</form>
<script>
function test()
{
var a=document.f;
if(a.txt) alert("存在")
else
alert("不存在")}
</script>

解决方案 »

  1.   

    <form name=f>
    <input type=radio name=txt>
    <input type=radio name=txt>
    <input type=radio name=txt>
    <input type=radio name=txt>
    <input type=button onclick="test()" vaLUE="TEST">
    </form>
    <script>
    function test()
    {
    var a=document.f;
    if(a.txt)
    alert("txt存在")
    else
    alert("txt不存在")if(a.txt2)
    alert("txt2存在")
    else
    alert("txt2不存在")
    }
    </script>
      

  2.   

    <form name=f>
    <input type=radio name=txt>
    <input type=radio name=txt>
    <input type=checkbox name=txt>
    <input type=checkbox name=txt>
    <input type=button onclick="test()" vaLUE="TEST">
    </form>
    <script>
    function test()
    {
    var a=document.f;
    if(a.txt)
    {
    for(i=0;i<a.txt.length;i++)
    {
    alert("有一个名为txt的"+a.txt[i].type);
    }
    }
    else
    alert("txt不存在")if(a.txt2)
    alert("txt2存在")
    else
    alert("txt2不存在")
    }
    </script>
      

  3.   

    简单改改如下:<form name=f>
    <input type=radio name=txt>txt
    <input type=radio name=txt>txt
    <input type=radio name=txt3>txt3
    <input type=radio name=txt4>txt4
    <input type=button onclick="test('txt')" vaLUE="test txt">
    <input type=button onclick="test('txt2')" vaLUE="text txt2">
    <input type=button onclick="test('txt3')" vaLUE="test txt3">
    <input type=button onclick="test('txt5')" vaLUE="text txt5">
    </form>
    <script>
    function test(strName){alert(strName+(document.f(strName)?"":"不")+"存在");}
    </script>