码迷,mamicode.com
首页 > Web开发 > 详细

js的几个案例

时间:2015-06-01 00:42:48      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

<html>
  <head lang="en">
      <meta charset="UTF-8">
      <title></title>
      <script type="text/javascript">
          function fun1(){
              alert("buchenggong");
              return false ;
          }
   
          function fun2(){
             return  confirm("你确定要提交吗?")
          }
   
          function fun3(){
  return confirm("你确定要重置吗?");
          }
   
      </script>
  </head>
  <body>
      <a href="http://www.baidu.com" onclick="return fun1()">baidu</a>
   
      <form action="" method="get">
   
          <input type="text" value = "hello"/>
          <input type = "submit" value="tijiao" onclick=" return fun2()" />
          <input type="reset" value = "重置" onclick="return fun3()"/>
      </form>
  </body>
  </html>
<html>
  <head lang="en">
      <meta charset="UTF-8">
      <title></title>
      <script type="text/javascript">
          function fun1(){
              alert("buchenggong");
              return false ;
          }
   
          function fun2(){
             return  confirm("你确定要提交吗?")
          }
   
          function fun3(){
  return confirm("你确定要重置吗?");
          }
   
      </script>
  </head>
  <body>
      <a href="http://www.baidu.com" onclick="return fun1()">baidu</a>
   
      <form action="" method="get">
   
          <input type="text" value = "hello"/>
          <input type = "submit" value="tijiao" onclick=" return fun2()" />
          <input type="reset" value = "重置" onclick="return fun3()"/>
      </form>
  </body>
 

</html>

 

  <!DOCTYPE html>
  <html>
  <head lang="en">
      <meta charset="UTF-8">
      <title></title>
      <script type="text/javascript">
          //var reg = /test/
   
          function fun1(){
              /*var reg = /test/g;
              var textA = document.getElementsByTagName("textarea")[0]
              var text = textA.value;
              alert(reg.source)
              reg.compile(/text/);
   
   
              var arr = text.match(reg);
              alert(arr);*/
  /*
              var reg = /test/gi
   
   
              var str = "asdfasdftest_Test-text";
   
              alert(reg.exec(str))
              alert(reg.exec(str))
              alert(reg.exec(str))
              alert(reg.lastIndex)*/
   
              var str = "ccccc ccc cccc ddd"
   
              var str = "csdfaaaaa.  aa  aa"
              var str ="\nwww.acombaidu.com"
   
              str = "ssdfkjSDFSDFab32132---csbkdf"
   
              //str = "today is tuesday how are you"
   
              //var reg = /([A-Z])|([0-9]+)/g;
   
   
              /*
              reg = /[^a-zA-Z0-9]+/g
   
             // reg.compile(/a\./g)
   
   
              alert(str.match(reg));
  */
  /*
   
              str = "158222656"
              str = document.getElementById("phone").value;
   
              //asdfasdfqq.com
   
              reg = /(([0-9a-z]){1,12})@(qq|sina|163)(\.com|\.cn)/g
   
              //reg =/^1[35789][0-9]{8}[0-9]$/;
              alert(reg.test(str));*/
   
   
              /*
              reg = /1[35789]\d{8}\d$/
              str = "test#$%$@#$_a   sdfsdfts5656jadflj"
              reg = /\S+/g
              str = "asdfas123FFSDFsdfsdfs##$#$dfd@.com"
              reg = /^\w{1,12}@(qq|sina|163)(\.com|\.cn)/
              //reg = /\s/g
              var arr = reg.test(str);
              alert(arr)
              //alert("|"+arr[0]+"|"+"|"+arr[1]+"|"+"|"+arr[2]+"|");*/
   
              str = "asdfhelloaaworldaa"
  /*
              0-255.0-255.0-255.0-255
              reg = /([1-9]|([1-9][0-9])|((1[0-9][0-9])|(2[0-4][0-9]|25[0-5]))\.){3}/
              reg =/aa(?!hello)/
              alert(reg.exec(str));
              /*
              str = "dd a3a3 ffddddaaaa baba3333 "
   
   
              str = str.replace(/([0-9a-z])\1{3}/g,"****");
              str = str.replace(/(\w)\1/g,"--")
              str = str.replace(/([a-z])([0-9a-z])\1\2/g,"#$#$")
              alert(str);
              /*
              //reg=/aa|dd/
              reg = /([a-z])([0-9])\1\2/g
              alert(str.match(reg));
   
              //alert(reg.exec(str));*/
   
              str = "alhsdkfjlkjHelloasdfworldhowasdf"
              str = "2+3.2-3*4/5=5;"
   
              //alert(str.split(/\/|\*|-|\+|=/));
   
              str = "asdf_"
              reg = /[0-9a-z_]+/;
   
              str = "adfaasdfsdfasdfsdafasdfasdf"
              reg = /^[a-z][a-z]{5,}[a-z]$/
              alert(reg.test(str));
              //asdfasdf *&(*&( sdf@qq.com
              //reg = /^[a-z0-9]\w{1,12}@(qq|sina|163)(\.com|\.cn)/
   
          }
   
   
   
   
   
      </script>
  </head>
  <body>
   
  <textarea cols="40" rows="5">
   
   
  </textarea>
   
  电话 :<input type="text" id="phone"/>
  <input type="button" onclick="fun1()" value="clickMe"/>
  </body>
  </html>

 

  <!DOCTYPE html>
  <html>
  <head lang="en">
      <meta charset="UTF-8">
      <title></title>
   
   
      <style type="text/css">
          .td{
              color: red;
              font-size: 13px;
          }
   
      </style>
      <script type="text/javascript">
          var str = [0,0,0,0]
   
          window.onload = function(){
   
              isNumOrChar("123123f")
              var inputs = document.getElementsByName("text")
              for(var i=0;i<inputs.length;i++){
                  inputs[i].onblur = function(){
                      var input = document.getElementById("tijiao")
                      var text = this.value.trim()
                      var tr = this.parentNode.parentNode;
                      var text1 = tr.cells[0].textContent;
                      var text2 = text1.substring(0,text1.length-1)
                      if(text.length==0&&(text2=="用户名"||text2=="密码")){
                          tr.cells[2].innerHTML = text2+"不能为空";
                          if(text2=="密码"){
                              str[1] = 0;
                          }else{
                              str[0] = 0;
                          }
                      }
                      else if(text.length<6&&(text2=="用户名"||text2=="密码"))
                      {
                          tr.cells[2].innerHTML = text2+"长度不能小于6";
                          if(text2=="密码"){
                              str[1] = 0;
                          }else{
                              str[0] = 0;
                          }
                      }
                      else if(isNumOrChar(text)&&(text2=="用户名"||text2=="密码")){
                          tr.cells[2].innerHTML = text2+"不能纯数字或者纯字母";
                          if(text2=="密码"){
                              str[1] = 0;
                          }else{
                              str[0] = 0;
                          }
                      }
                      else if(text2=="邮箱"&&text.length==0){
                          tr.cells[2].innerHTML = text2+"不能为空";
                          str[2] = 0;
                      }
                      else if(text2=="邮箱"&&isNotEmail(text))
                      {
                          tr.cells[2].innerHTML = text2+"格式不正确";
                          str[2] = 0;
                      }
                      else if(text2=="手机"&&text.length==0)
                      {
                          tr.cells[2].innerHTML = text2+"不能为空";
                          str[3] = 0;
                      }else if(text2=="手机"&&isNotPhone(text))
                      {
                          tr.cells[2].innerHTML = text2+"格式不正确";
                          str[3] = 0;
                      }
                      else{
                          tr.cells[2].innerHTML = "";
                          switch (text2){
                              case "手机":
                                  str[3] = 1;
                                      break;
                              case "邮箱":
                                  str[2] = 1;
                                      break;
                              case "用户名":
                                  str[0] = 1;
                                      break;
                              case "密码":
                                  str[1] = 1;
                                      break;
                          }
                      }
   
                      if(str.toString()=="1,1,1,1"){
                          input.disabled = false;
                      }else{
                          input.disabled = true;
                      }
                  }
              }
          }
   
          function isNumOrChar(str){
   
              var reg = /^\d\d{4,}\d$/g
              var reg1 = /^[a-z][a-z]{4,}[a-z]$/g
   
             return (reg.test(str)||reg1.test(str))
          }
   
          function isNotEmail(str){
              var reg = /^\w\w{5,12}@(qq|sina|163)(\.com|\.cn)/g
              return !reg.test(str);
          }
   
          function isNotPhone(str){
              var reg = /^1[35789]\d{8}\d$/
              return !reg.test(str)
          }
   
      </script>
  </head>
  <body>
      <form>
          <table>
              <tr>
                  <td>用户名:</td>
                  <td><input type ="text" name = "text"/></td>
                  <td class="td"></td>
              </tr>
              <tr>
                  <td>密码:</td>
                  <td><input type ="password" name = "text"/></td>
                  <td class="td"></td>
              </tr>
              <tr>
                  <td>邮箱:</td>
                  <td><input type ="text" name = "text"/></td>
                  <td class="td"></td>
              </tr>
   
              <tr>
                  <td>手机:</td>
                  <td><input type ="text" name = "text"/></td>
                  <td class="td"></td>
              </tr>
              <tr>
                  <td></td>
                  <td colspan="2">
                      <input type="submit" value="submit" disabled = "disabled" id="tijiao"/>
                      <input type="reset" value="reset"/>
                  </td>
   
              </tr>
          </table>
   
      </form>
  </body>
  </html>

js的几个案例

标签:

原文地址:http://www.cnblogs.com/zhoukui224466/p/4542904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!