zoukankan      html  css  js  c++  java
  • JS判断文本框内的内容是否为空

    View Code
     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 
     3 <html xmlns="http://www.w3.org/1999/xhtml">
     4 <head>
     5     <title></title>
     6 </head>
     7 <body>
     8     <script type="text/javascript">
     9         function JTrim1(s) {
    10             return s.replace(/(^\s*)|(\s*$)/g, "");
    11         }
    12 
    13         function JTrim2(s) {
    14             return s.replace(/\s+/g, "");
    15         }
    16 
    17         function validator1() {
    18             var var1 = document.getElementById("1");
    19             if (JTrim1(var1.value) == "")
    20                 alert("对不起,你没有输入内容");
    21             else
    22                 alert("你输入了内容");
    23         }
    24 
    25         function validator2() {
    26             var var1 = document.getElementById("1");
    27             if (JTrim2(var1.value) == "")
    28                 alert("对不起,你没有输入内容");
    29             else
    30                 alert("你输入了内容");
    31         }       
    32     </script> 
    33     <input type= "text" id= "1" value=""/> 
    34     <br />    
    35     <input type="button" name="name" value="vaildator1()" onclick= "validator1();" />
    36     <br />       
    37     <input type="button" name="name" value="vaildator2()" onclick= "validator2();" />
    38     <br />   
    39 </body>
    40 </html>
  • 相关阅读:
    Docker学习总结(一)--Docker简介
    Liunx软件安装之Zabbix监控软件
    Liunx软件安装之Nginx
    Liunx软件安装之Redis
    Liunx软件安装之Tomcat
    Liunx软件安装之JDK
    Liunx软件安装之MySQL
    Liunx学习总结(九)--防火墙
    tensorflow 错误
    anaconda安装失败
  • 原文地址:https://www.cnblogs.com/dianyitongxiao/p/2747835.html
Copyright © 2011-2022 走看看