你好,我是 javascript 和 jquery 的初学者,我收到了这个错误:
无法读取未定义的属性(读取“长度”)
我不知道如何解决这个问题。如何解决此错误?
这是我的js文件:
var fname, lname, organization, designation, email, m_number;
$('#proceedBtn').on('click', function(event) {
fname = $('#fname').val();
lname = $('#lname').val();
email = $('#email').val();
phone = $('#m_number').val();
organization = $('#organization').val();
designation = $('#designation').val();
//set it to true
var isProceed = true;
if (fname.trim() === "" || fname.length < 2) {
alertify.error('Please input your first name');
isProceed = false;
}
if (lname.trim() === "" || lname.length < 2) {
alertify.error('Please input your last name');
isProceed = false;
}
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
var emailValid = re.test(String(email).toLowerCase());
if (email.trim() === "" || email.length < 3 || !emailValid) {
alertify.error('Please check your email');
isProceed = false;
}
if (m_number === "" || m_number.length < 3) {
alertify.error('Please input your phone');
isProceed = false;
}
if (organization.trim() === "" || organization.length < 2) {
alertify.error('Please input your organization');
isProceed = false;
}
if (designation.trim() === "" || designation.length < 2) {
alertify.error('Please input your designation');
isProceed = false;
}
if (isProceed) {
procceedBTN();
// $('html, body').animate({scrollTop: '0px'}, 0);
}
})