課程
/前端開發
/JavaScript
/JavaScript進階篇
密碼:<input name="password" type="password" >
2018-12-12
源自:JavaScript進階篇 6-3
正在回答
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠標經過事件 </title>
<script type="text/javascript">
? ? function inputTEXT(){
? ? ? ? var x=document.getElementById("text").value;
? ? ? ? if(x==""){
? ? ? confirm("請輸入密碼后,再單擊確定!");
? ? ? }
? ? ? 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?按鈕,結合onclick事件,驗證和提交表單 ??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("用戶名長度必須介于5-50個字符之間!"); ????????}else{????????????//使用form對象的submit()方法,實現提交。????????????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("請輸入密碼后,再單擊確定!");????? }????? 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>
懂了,想取密碼框的值,可以先給控件設置ID,通過讀取ID的值來查看密碼框的值。
分享給和我一樣初學的小伙伴
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
3 回答判斷輸入是否為空,但運行不管輸入是否為空,都會執行?
1 回答第一個for循環怎么判斷的是否為復選框
2 回答能不能直接判斷input的type屬性是否為復選框
1 回答如何判斷選中的是復選款
2 回答求js如何不用正則就能判斷文本框輸入內容為數字
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2020-01-10
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> 鼠標經過事件 </title>
<script type="text/javascript">
? ? function inputTEXT(){
? ? ? ? var x=document.getElementById("text").value;
? ? ? ? if(x==""){
? ? ? confirm("請輸入密碼后,再單擊確定!");
? ? ? }
? ? ? 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("請輸入密碼后,再單擊確定!");
????? }
????? 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>
懂了,想取密碼框的值,可以先給控件設置ID,通過讀取ID的值來查看密碼框的值。
分享給和我一樣初學的小伙伴