我試圖在HMTL聯繫表單中使用javascript,直到鼠標點擊其中一個字段才顯示字段中的文本。然而,我的PHP似乎仍然認爲,只有javascript而不是物理HTML時,字段中才有文本。有人可以幫我解決這個問題嗎?爲什麼我的JavaScript混淆了我的php
的JavaScript/HTML表單
<form method="post" action="sendEmail.php">
<input type="text" name="name" id="name" onfocus="if (this.value == 'Your Name')
this.value = '';" onblur="if (this.value == '') this.value = 'Your Name';" maxlength="30"
value="Your Name" />
<input type="text" name="email" id="email" onfocus="if (this.value == 'Your Email')
this.value = '';" onblur="if (this.value == '') this.value = 'Your Email';" maxlength="30"
value="Your Email" />
<br /><br />
<textarea name="message" id="comments" value="Enter Your Message Here..." cols="60" rows="5"
onfocus="if (this.value == 'Enter Your Message Here...') this.value = '';"
onblur="if (this.value == '') this.value = 'Enter Your Message Here...';" >Enter Your Message Here...</textarea>
</form>
PHP
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+][email protected][a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 5) {
$error['comments'] = "Messages must be longer then 5 characters";
}
提示:您可能有興趣瞭解[漸進式增強](http://www.alistapart.com/articles/understandingprogressiveenhancement)和[結構,演示和行爲的分離](http://www.alistapart .com/articles/behaviralralseparation) – Herbert