此JavaScript檢查name-text
框是否爲空。如何將一些文本添加到文本框
如果爲空,然後在同一行應該有「需要名稱」追加。
function checkFields(){
var name = document.forms["contact-form"]["name"].value;
if(name == ""){
}
<!--- This is the html code for text box for name and submit button to call checkFields() method -->
<div class="required-fields">
<label>My Name:</label>
<input type="text" name="name"/>
</div>
<input type="button" onclick="checkFields()" value="Send Message"/>
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation – epascarello