免费人妻精品一区二区三区-人人玩人人添人人澡东莞-很黄很色很污18禁免费-视频一区二区三区四区五区-久久99精品久久久久久9-国产97色在线 | 国-伊人七七-已婚少妇美妙人妻系列-欧美俄罗斯乱妇-奇米在线-国产精品99久久精品爆乳-欧美精品乱码视频一二专区-又大又爽又黄无码a片-粉嫩绯色av一区二区在线观看-国产爆乳无码av在线播放

form表單提交和阻止

2016/11/29 8:37:13   閱讀:1868    發布者:1868
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <style type="text/css"></style> <script type="text/javascript"> //實例:submit按鈕,結合onsubmit事件,驗證和提交表單 function checkForm(){ //判斷用戶名和密碼是否為空 if(document.form1.username.value==""){ window.alert("用戶名不能為空"); return false; }else if(document.form1.username.value.length<5 ||
document.form1.username.value.length
>20){ window.alert("用戶名在5-20位"); return false; }else if(document.form1.userpwd.value==""){ window.alert("密碼不能為空"); return false; }else if(document.form1.userpwd.value.length<5 ||
document.form1.userpwd.value.length
>20){ window.alert("密碼必須在5-20位"); return false; } } </script> </head> <body> <form name="form1" method="get" action="login.php" onsubmit="return checkForm()"> 用戶名:<input type="text" name="username" /> 密碼:<input type="password" name="userpwd" /> <input type="submit" value="提交表單" /> </form> //單機以下的鏈接,不會跳轉網址,因為默認動作被阻止了 <a href="http://www.itcast.cn" onclick="return false">北京交通網</a> </body> </html>

onsubmit="return checkForm()" 加return是事件返回事件,當返回值為false的時候會阻止表單提交。

事件返回值:

事件的返回值,會影響事件的默認動作。

如果事件的返回值為false,則阻止默認動作執行。

如果事件返回值為ture或空,則默認動作執行。

如果事件沒有任何返回值,則默認動作執行。

受影響的事件有兩個:onclickonsubmit

其他事件的返回值,不會影響默認動作。

onclick的返回值也會組織submit的提交。