onSubmit的使用
onSubmit的使用
在web開發中,我們經常會遇到,一點回車鍵表單就自己提交的問題,能不能禁用回車鍵呢,答案是肯定的.?
Html代碼??
<from action="" method="post" onSubmit="return false">???
...............????
</from>??
如果想在表單提交時,進行驗證?
Html代碼??
<html>???
<head>???
<script lanuage="javascript">???
??function check()????
{????
//驗證不通過時????
return false;????
}????
</script>???
</head>???
<body>???
<from action="" method="post" onSubmit="return check()">???
...............????
</from>???
</body>???
</html>??
<html>?
<head>?
<script lanuage="javascript">?
??function check()?
{?
//驗證不通過時?
return false;?
}?
</script>?
</head>?
<body>?
<from action="" method="post" onSubmit="return check()">?
...............?
</from>?
</body>?
</html>
?
這樣就會對表單進行驗證再進行提交?
要注意的是,千萬不能寫成?
Html代碼??
<from action="" method="post" onSubmit="check()">???
...............????
</from>??
因為check()不通過后會返回false, 因為onsubmit屬性就像是<form>這個html對象的一個方法名,其值(一字符串)就是其方法體,默認返回true,所以還是相當于驗證通過??
記得對表單驗證一定要寫成這樣?
Html代碼??
<from action="" method="post" onSubmit="return check()">???
...............????
</from>
總結
以上是生活随笔為你收集整理的onSubmit的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP用gd库给图片添加水印,php用G
- 下一篇: java多属性的map_java - 具