注册页面中的元素要根据条件显示和隐藏,所以现在要是加验证的话只能对页面中显示的元素加验证,研究几天了也没搞定望各位前辈指点下,谢谢了……

解决方案 »

  1.   

    <!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=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready( function() {
    $("#s1").hide();
    $("#myForm").submit( function() {
    if ($("#t1").is(":visible")) {
    //可见元素,开始验证
    alert('t1');
    }
    if ($("#s1").is(":visible")) {
    //此元素是隐藏的,因此不执行下面的验证代码
    alert('s1');
    }
    return false;
    });
    });
    </script>
    </head><body>
    <form id="myForm">
    <input type="text" id="t1" name="t1" />
    <select id="s1" name="s1" style="display:none;">
    <option value="default">DEFAULT</option>
    </select>
    <input type="submit" value="提交" />
    </form>
    </body>
    </html>