var flag = true; if (document. getElementById("txtName").value == "") { xtEmail").value = = "") { ; 🎜>-->But how? There are many fields that need to be verified, there will be a lot of ifs, and they are not elegant at all
function FormField(fieldName, fieldDesc) {//Encapsulate the changer attribute fields and descriptions this.fieldName = fieldName; this.fieldDesc = fieldDesc; } String.prototype.MyTrim = function () {//Remove leading and trailing spaces . > var oUl = document.getElementById("ulError"); oUl.innerHTML = ""; var list = new Array ( //You only need to verify that it is empty in the future Just add an object to the array new FormField("name", "username"), new FormField("email", "mail") var flag = true; eval operation if (fv == null ||!fv.MyTrim()) { fieldDesc " Cannot be empty liError.innerHTML =list[i].fieldDesc " Cannot be empty"; 🎜>
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn