2
我想驗證HTML表單的每個字段onblur。驗證消息得到顯示,但不跨越框的整個水平空間。 我希望它是這樣的。Validation Message on HTML form will in line
Customer Name: TextBox *Customer Name Must Not Be Blank
但它顯示:
Customer Name: TextBox *Customer
Name Must
Not Be
Blank
這是我的代碼:
<form method="post" name="customer" action="newcustcheck.php" onblur="return Validate()"
onKeyUp="return Validate()">
<table width="300">
<tr>
<td>Customer Name:</td>
<td><input type="text" name="name" ></td>
<td> <label class="message" id="message" ></td>
</tr>
</table>
</form>
CSS
form {
width: 400px;
background:#FFD700;
color: #000000;
font: small Verdana, sans-serif;
position: absolute;
top: 200px;
left: 550px;}
.message{color:#FF0000;
font-size: small;
font-weight: bold; }
的JavaScript
function Validate(){
if(x==null || x==""){
document.getElementById('message').style.visibility="visible";
document.getElementById('message').innerHTML="Customer Name must not be blank";
}
else{
document.getElementById('message').style.visibility="hidden";
}
}
你給表格400像素寬度和形式只有300像素是什麼問題? – AMember
400px是窗體的大小,300px是文本框的大小。我想在左邊的100像素空間中顯示錯誤信息。 – user3402248
錯誤信息沒有足夠的空間。你想讓它溢出黃色塊? – dfsq