form的onsubmit事件--表單提交前的驗證最佳實現方式

function check(){
   var name = document.getElementById("name").value;
   if(name ==  null || name == ''){
        alert("用戶名不能爲空");
        return false;
   }
   return true;
}


<form name="form" action="跳轉的頁面" method="post"  onsubmit="return check()">
  <input type="text" id="name"/>
  <input type="sumit" value="提交"/>
</form>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章