$(object).css('background-color','red'无效

时间:2012-11-12 10:27:22

标签: css

我有一个接受电子邮件地址的模式表单。然后,我验证了这一点,并希望突出显示电子邮箱,如果无效。但是使用.css('background-color','red')并没有做任何事情。我试过驼峰case'backgroundColor',但这没有任何区别。代码正在通过else路径'因为我正在收到警报。这是代码:

$( "#dialog-form" ).dialog({
        autoOpen: false,
        height: 300,
        width: 350,
        modal: true,
        buttons: {
            "Send": function() {

                if (validateEmail($('#email').val()))
                {
                var datastr = 'name=' + $('#name').val() + '&email=' + $('#email').val() + '&enquiry=' + $('#enquiry').val() + '&recip=' + eMail;

                $.ajax({
                type: "POST",
                url: "email.php",
                data: datastr,
                cache: false,
                success: function(html){
                        alert ("Email has been Sent");
                        }
                });

                $( this ).dialog( 'close' );
                }
                else
                {
                $('#email').css('background-color','red');
                alert('Your Email Address is invalid');
                }
             },
            Cancel: function() {
                $( this ).dialog( 'close' );
             }},
        close: function() {
           $( this ).dialog('destroy');
        }
    });

这里有表格:

<div id="dialog-form" title="Contact Computer Rep" style="display: none">
<form>
    <div tal:condition="data/userlevel"><span>Your Name:</span><span tal:content="data/displayname"></span><br />
        <span>Your Email Address:</span><span tal:content="data/mail"></span>
    </div>
<fieldset>
    <span tal:condition="not: data/userlevel">
    <label for="name">Your Name</label>
    <input type="text" name="name" id="name" value="" class="text ui-widget-content ui-corner-all" />
    <label for="email">Your Email Address</label>
    <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
    </span>
    <label for="enquiry">Your Enquiry</label>
    <input type="text" name="enquiry" id="enquiry" value="" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>

2 个答案:

答案 0 :(得分:1)

jQuery了解background-colorbackgroundColor。尝试使用RGB值而不是red,例如:

$('#email').css('background-color', '#f00');

答案 1 :(得分:0)

您是否可以验证该电子邮件是否是您的电子邮箱的ID。 你也可以试试$('#email').css({'background-color': 'red'});