我有这个代码,它显示我的错误,我正在尝试设置下面的三个验证,请更正下面的错误..这可能吗?
if (name == '' || name.length <= 2) {
valid = '<p>Your name' + required +'</p>';
}
if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p>Your email' + required +'</p>';
}
if (mydropdown == '') {
valid += '<p>An item from the list' + required +'</p>';
}
// let the user know if there are erros with the form
if (valid != '') {
$('form #response').removeClass().addClass('error strong')
.html('<strong>Please correct the errors below.</strong>' +valid).fadeIn('fast');
}
答案 0 :(得分:1)
在<p>
标记中添加一个类,并使用CSS添加样式。
if (name == '' || name.length <= 2) {
valid = '<p class="error">Your name' + required +'</p>';
}
if (!email.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
valid += '<p class="error">Your email' + required +'</p>';
}
if (mydropdown == '') {
valid += '<p class="error">An item from the list' + required +'</p>';
}
在CSS文件中:
p.error {
color: red;
font-weight: bold;
/* whatever style you want */
}