0

我有这段代码,它显示了我的错误,我正在尝试设置以下三个验证的样式,请更正下面的错误..这可能吗?

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');   


    }
4

1 回答 1

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 */
}
于 2012-12-29T00:18:44.800 回答