課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
密碼:<input name="password" type="password" >
2018-12-12
源自:JavaScript進(jìn)階篇 6-3
正在回答
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠標(biāo)經(jīng)過(guò)事件 </title>
<script type="text/javascript">
? ? function inputTEXT(){
? ? ? ? var x=document.getElementById("text").value;
? ? ? ? if(x==""){
? ? ? confirm("請(qǐng)輸入密碼后,再單擊確定!");
? ? ? }
? ? ? else{
? ? ? ? ? alert("提交成功!");
? ? }
</script>
</head>
<body>
<form>
密碼:<input name="password" type="password" id="text"><br> <br>?
<input name="確定" type="button" value="確定" onclick="inputTEXT()"/>
</form>
</body>
</html>
<script?type="text/javascript"> ??//button?按鈕,結(jié)合onclick事件,驗(yàn)證和提交表單 ??function?checkForm(){????????//判斷用戶名是否為空 ????????if(document.form1.username.value==""){ ????????????????window.alert("用戶名不能為空"); ????????}else?if(document.form1.username.value.length<5?||?document.form1.username.value.length>20){ ????????????window.alert("用戶名長(zhǎng)度必須介于5-50個(gè)字符之間!"); ????????}else{????????????//使用form對(duì)象的submit()方法,實(shí)現(xiàn)提交。????????????document.form1.submit();???????? ????????} ??}?</script> ?</head> ?<body> ??<form?name="form1"?method="get"?action="login.php"> ??用戶名:<input?type="text"?name="username"?/> ??密碼:<input?type="password"?name="userpwd"?/> ??<input?type="button"?value="提交表單"?onclick="checkForm()"?/> ??</form> ?</body>
<script type="text/javascript">??? function message(){????? var pwd=document.getElementById("password").value;????? if(!pwd){????? confirm("請(qǐng)輸入密碼后,再單擊確定!");????? }????? else{????????? alert("succeed login in");????? }?????? ???? }</script></head><body><form>密碼:<input name="password" type="password" id="password"><input name="確定" type="button" value="確定" onclick="message()"/></form></body></html>
懂了,想取密碼框的值,可以先給控件設(shè)置ID,通過(guò)讀取ID的值來(lái)查看密碼框的值。
分享給和我一樣初學(xué)的小伙伴
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁(yè)動(dòng)態(tài)交互世界
3 回答判斷輸入是否為空,但運(yùn)行不管輸入是否為空,都會(huì)執(zhí)行?
1 回答第一個(gè)for循環(huán)怎么判斷的是否為復(fù)選框
1 回答如何判斷選中的是復(fù)選款
2 回答能不能直接判斷input的type屬性是否為復(fù)選框
2 回答復(fù)選框判斷問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2020-01-10
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠標(biāo)經(jīng)過(guò)事件 </title>
<script type="text/javascript">
? ? function inputTEXT(){
? ? ? ? var x=document.getElementById("text").value;
? ? ? ? if(x==""){
? ? ? confirm("請(qǐng)輸入密碼后,再單擊確定!");
? ? ? }
? ? ? else{
? ? ? ? ? alert("提交成功!");
? ? ? }
? ? }
</script>
</head>
<body>
<form>
密碼:<input name="password" type="password" id="text"><br> <br>?
<input name="確定" type="button" value="確定" onclick="inputTEXT()"/>
</form>
</body>
</html>
2019-08-17
2018-12-12
<script type="text/javascript">
??? function message(){
????? var pwd=document.getElementById("password").value;
????? if(!pwd){
????? confirm("請(qǐng)輸入密碼后,再單擊確定!");
????? }
????? else{
????????? alert("succeed login in");
????? }
?????? ?
??? }
</script>
</head>
<body>
<form>
密碼:<input name="password" type="password" id="password">
<input name="確定" type="button" value="確定" onclick="message()"/>
</form>
</body>
</html>
懂了,想取密碼框的值,可以先給控件設(shè)置ID,通過(guò)讀取ID的值來(lái)查看密碼框的值。
分享給和我一樣初學(xué)的小伙伴