![](/img/trans.png)
[英]jQuery/Javascript - Get value of text input field, and display in div
[英]Get input field value and display it in a div using javascript
我在提交表單后嘗試在div中顯示輸入字段值。但是我無法做到。
我做錯了什么?
有人能幫助我嗎?
function validate() { var a = document.forms["Form"]["uname"].value; var validation=true; if ((a == null || a == "")||(!a.match(/^([a-zA-Z]{2,30})$/))) { document.getElementById('uname').className = 'box'; document.getElementById('popup').innerHTML= document.getElementById('uname').value; validation=false; } else{ document.getElementById('uname').className = ''; } return validation; }
.box { border: 2px solid red; } #popup { width:25%; height:115px; background-color: red; margin-top:2% ; margin-left: 60%; color: black; }
<head> </head> <body> <form method="post" name="Form" onsubmit="return validate()" action="" id="form_id"> <label>NAME:</label> <input type="text" name="uname" id="uname" class="fields" > <button type="submit" name="submit">SUBMIT</button> <div id="popup"></div> </form> </body>
問題是if else條件。 內部html應該處於其他狀態
if ((a == null || a == "")||(!a.match(/^([a-zA-Z]{2,30})$/))) {
document.getElementById('uname').className = 'box';
validation=false;
} else{
document.getElementById('uname').className = '';
document.getElementById('popup').innerHTML= document.getElementById('uname').value;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.