Chrome Pointer

2019年9月24日 星期二

Javascript 的 document.getElementById("name").value.length 語法分享 !

<!DOCTYPE html>
<!-- Website template by freewebsitetemplates.com -->
<html>
<head>
 <meta charset="UTF-8">
 <title>High Fashion Website Template</title>
 <link rel="stylesheet" href="css/style.css" type="text/css">
 <!--[if IE 7]>
  <link rel="stylesheet" href="css/ie7.css" type="text/css">
 <![endif]-->
 
 
 
 <script type="text/javascript">
 <!--

 function form_action()
 {
  
  var m = document.getElementById("name").value.length;
                        //取得ID為"name"的長度.
                          當你在框框內輸入字串後,按下submit鍵後,就取得長度~
                          這個javascript的語法要背喔!!

  if (m<4)  //長度小於4時,跳出帳號太短了彈跳窗
  {
   
   alert("帳號太短了");
   return false; //若回傳false則不會執行action="0924_2.php"
  }
  else
  {
   alert("成功!!");
   return true; //若回傳true則會執行action="0924_2.php"
  }
 }
//-->
</script>
 

</head>
<body>
 
<form action="0924_2.php" method="POST" onsubmit="return form_action()">
  <input type="text" name="Keyword" id="name" maxlength="10">    
  <input type="submit" value="OK">
 </form>
 
 
</body>
</html>

帳號長度小於4時的結果
 當帳號大於4時就顯示"成功"~

沒有留言:

張貼留言

喜歡我的文章嗎? 喜歡的話可以留言回應我喔! ^^