0
    $("#frmNewList").validate({
    rules:{
    price:{
                        required: true, 
                        number: true
                          }
          },
    messages: {
    price:{ 
                        required: "Please Enter The Price",
                        number: "Please Enter the amount only"
                         }
              },
    errorPlacement:function(f,g){
             if(g.attr('id')=='price')
              {
                f.addClass('margin');
                f.css({'margin-left':'-10px !important'});
             }

    });
<style>
.margin{margin-left:-10px !important;
}
</style>

这里我有两个问题:1)我想应用代码中显示的 -10px 边距,但它不起作用。2)我添加了代码中显示的边距类。两者都是单独添加的。但两者都不起作用。

4

1 回答 1

3

!important不适用于 JQuery css

更改您的代码

f.css({'margin-left':'-10px !important'});

f.css({'margin-left':'-10px'});

演示:http: //jsfiddle.net/BrzM9/1/

更新:当然可以使用margin-top

$("#div1").css({'margin-left':'-10px', 'margin-top':'-20px'});

演示:http: //jsfiddle.net/hFZs9/3/

于 2013-05-31T11:02:41.267 回答