form表單提交和阻止

2022-06-17    分類: 網(wǎng)站建設(shè)

<!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按鈕,結(jié)合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> //單機(jī)以下的鏈接,不會跳轉(zhuǎn)網(wǎng)址,因為默認(rèn)動作被阻止了 <a onclick="return false">北京交通網(wǎng)</a> </body> </html>

名稱欄目:form表單提交和阻止
網(wǎng)頁鏈接:http://www.bm7419.com/news10/168510.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、App設(shè)計動態(tài)網(wǎng)站、小程序開發(fā)企業(yè)網(wǎng)站制作、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站