Check out the jsFiddle : http://jsfiddle.net/zpNSv/1/<form name="form" id="form" method="post" action=""> <p class="FirstName"> <label for="FirstName">First Name:</label> </p> <p> <input name="FirstName" type="text" id="FirstName" /> </p> <p class="LastName"> <label for="LastName">Last Name:</label> </p> <p> <input name="LastName" type="text" id="LastName" /> </p> <p class="submit"> <input name="submitButton" type="button" id="submitButton" value="Get Name" onClick="alert(getName())" /> </p> </form> AND JS function getName() { var FirstName = document.getElementById("FirstName"), LastName = document.getElementById("FirstName"); if (FirstName.value == "" || document.getElementById("LastName").value == "") { return ("Please enter a first name and a last name."); } else { var FullName = FirstName.value + ' ' + LastName.value; return FullName; }} 这篇关于表格和getElementById的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 22:14