丁香花完整视频在线观看-午夜爽爽爽-亚洲777-女同一区二区-国产伊人网-国产乱码精品一品二品-天堂色av-伊人影院av-午夜中文字幕-久久精品片-男女视频在线观看免费-中文字幕久久网-欧美www视频-非洲黑妞xxxxhd精品-亚洲午夜精品在线-亚洲中午字幕-精品国产aⅴ-日本高清视频在线-成年人免费大片-亚洲精品视频在线免费

form表單提交和阻止

2016/11/29 8:37:13   閱讀:1870    發(fā)布者:1870
<!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"> //實(shí)例:submit按鈕,結(jié)合onsubmit事件,驗(yàn)證和提交表單 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> //單機(jī)以下的鏈接,不會(huì)跳轉(zhuǎn)網(wǎng)址,因?yàn)槟J(rèn)動(dòng)作被阻止了 <a href="http://www.itcast.cn" onclick="return false">北京交通網(wǎng)</a> </body> </html>

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

事件返回值:

事件的返回值,會(huì)影響事件的默認(rèn)動(dòng)作。

如果事件的返回值為false,則阻止默認(rèn)動(dòng)作執(zhí)行。

如果事件返回值為ture或空,則默認(rèn)動(dòng)作執(zhí)行。

如果事件沒有任何返回值,則默認(rèn)動(dòng)作執(zhí)行。

受影響的事件有兩個(gè):onclickonsubmit

其他事件的返回值,不會(huì)影響默認(rèn)動(dòng)作。

onclick的返回值也會(huì)組織submit的提交。