zoukankan      html  css  js  c++  java
  • 关于验证控件和javaSript验证的共存问题


            以前一直用验证控件来验证输入格式是否正确,感觉用起来还行。后来有了新的需求,就是两个可以填入任意一个就行,比如说固定电话和手机添一个就可,所以就加了段js如下:
          this.BtnSave.Attributes.Add("onclick", "return SubmitTelAndMobile()");
          //SubmitTelAndMobile函数如下
          function SubmitTelAndMobile()
         {
            var tel=document.getElementById("TBMophileNo").value.replace(/(^\s+)|\s+$/g,"");
            var mobile=document.getElementById("TBtel").value.replace(/(^\s+)|\s+$/g,"");
          
            if(tel=="" && mobile=="")
            {
                alert("手机号和固定电话不能同时为空");
                return false;
            }
            else
            {
                return true;
            }
         }
          以为这样可以万事大吉了,可一测试出现问题了,js脚本管用,但验证控件不管用了,我又突然想到一个button的客户端的方法OnClientClick,加上OnClientClick="SubmitTelAndMobile()",在去掉 this.BtnSave.Attributes.Add("onclick", "return SubmitTelAndMobile()"),一测试搞定,呵呵!!
          不知道大家遇到过这种情况没有?
  • 相关阅读:
    zoj 2876 Phone List
    zoj 2829 Beautiful Number
    zoj 2723 Semi-Prime(set)
    zoj 2835 Magic Square(set)
    zoj 2818 Root of the Problem
    zoj 2744 Palindromes
    zoj 1109 Language of FatMouse(map)
    zoj 2724 Windows Message Queue
    zoj 2722 Head-to-Head Match(两两比赛)
    zoj 2727 List the Books
  • 原文地址:https://www.cnblogs.com/zhangzheny/p/623542.html
Copyright © 2011-2022 走看看