我正在處理聯繫表單,並需要一些內嵌的JavaScript表單驗證。我已經有了PHP驗證,但是我想要在http://twitter.com/signup上進行一些有效的表單驗證。我希望在輸入後顯示並隱藏p
標籤。這是我的html代碼。內嵌有效Javascript表單驗證
<form class="contact" method="POST" enctype="multipart/form-data" action="validate.php">
<label for="fname">First Name*<br /></label>
<input type="text" id="fname" style="font-family: Gochi Hand;" name="fname" placeholder="First" autofocus required autocomplete="on" />
<div class="notices">
<p id="helper" style="color:green;" class="g-notice">First Name Looks Good.</p>
<p id="helper" style="color:red;" class="r-notice">A First Name is required.</p>
<p id="helper" style="color:#0099FF;" class="h-notice">Enter Your First Name.</p>
</div>
<br /><br />
<label for="lname">Last Name*<br /></label>
<input type="text" id="lname" style="font-family: Gochi Hand;" name="lname" placeholder="Last" required autocomplete="on" />
<div class="notices">
<p id="helper" style="color:green;" class="g-notice" style="color:green; ">Last Name Looks Good.</p>
<p id="helper" style="color:red;" class="r-notice">A Last Name is required.</p>
<p id="helper" style="color:#0099FF;" class="h-notice">Enter Your Last Name.</p>
</div>
<br /><br />
<label for="email">Email Address*<br /></label>
<input type="email" name="email" style="font-family: Gochi Hand;" id="email" placeholder="[email protected]" pattern="^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$" required autocomplete="on" />
<div class="notices">
<p id="helper" style="color:green;" class="g-notice">Email Looks Good.</p>
<p id="helper" style="color:red;" class="r-notice">A Email is required.</p>
<p id="helper" style="color:#0099FF;" class="h-notice">Enter Your Email.</p>
</div>
<br /><br />
<label for="url">Website<br /></label>
<input type="url" name="url" id="url" style="font-family: Gochi Hand;" placeholder="http://website.com" pattern="^(http|https)://.+(.[a-zA-Z])$" autocomplete="on" />
<div class="notices">
<p id="helper" style="color:green;" class="g-notice">URL Looks Good.</p>
<p id="helper" style="color:#0099FF;" class="h-notice">Enter Your URL.</p>
</div>
<br /><br />
<label for="age">Age*<br /></label>
<input type="text" size="3" id="age" name="age" style="font-family: Gochi Hand;" required class="age" required placeholder="Age" pattern="^\d+$" autocomplete="on" />
<div class="notices">
<p id="helper" style="color:green;" class="g-notice">Age Looks Good.</p>
<p id="helper" style="color:red;" class="r-notice">An Age is required.</p>
<p id="helper" style="color:#0099FF;" class="h-notice">Enter Your Age.</p>
</div>
<br /><br />
<label for="comments">Comments*<br /></label>
<textarea style="font-family: Gochi Hand;" required id="comments" name="comments" cols="30" rows="10"></textarea>
<br /><br />
<input type="hidden" value="True" name="go" id="go" />
<input style="color:red;" type="submit" class="submit" value="Send!" />
</form>
任何建議或幫助將值得一噸。
謝謝。我會嘗試這個,但現在我用PHP來做幾乎完成相同的事情 –