表单中的联系方式有手机和座机两种,我想让用户必须填写其中的一项,而另一项可以不填,应该怎样写判断程序呢,谢谢

解决方案 »

  1.   


    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <script language="javascript">
    function check_data(){
    var f = document.forms[0];
    if (f.phone.value == "" && f.move.value == ""){
    alert("“手机”或“座机”两个必须填一个!");
    return false;
    }
    return true;
    }
    </script>
    </head><body><form method="POST" action="******" onsubmit="return check_data();">
    <p>座机:<input type="text" name="phone" size="20"></p>
    <p>手机:<input type="text" name="move" size="20"></p>
    <p><input type="submit" value="提交"></p>
    </form></body></html>