如何用jquery设置保证金?
问题描述:
我这样做:
var sId=id.toString();
var index=sId.substring(3);
var mrg=index*221;
var el=$(id);
el.css('margin-left',mrg+'px'); and el.css('marginLeft',mrg+'px');
el是我想要设置边距(正确检索)的元素,而mrg是值新保证金
el is the element i want to set the margin to (correctly retrieved) and mrg is the value of the new margin
如果我做$ ('#test1')。css('margin-left',200);
或 $('#test1')。css('marginLeft',200);
它以两种方式工作,我设置属性的方式有问题。
If i do $('#test1').css('margin-left',200);
or $('#test1').css('marginLeft',200);
it works in both ways, it's something wrong with the way i set the property.
正确的方法是var el = $('#'+ id);
The correct way is var el=$('#'+id);
答
尝试
el.css('margin-left',mrg+'px');