[英]jQuery unexpected token due to margin-left
I am editing the css values of some elements via jQuery, when I attempted to change the margin-left value of an element, resulting in an "Unexpected token" error due to the "-" in margin-left. 当我尝试更改某个元素的margin-left值时,我正在通过jQuery编辑某些元素的css值,由于margin-left中的“-”导致出现“意外令牌”错误。 Is there a means of changing the margins via jquery without resulting in this error?
有没有一种方法可以通过jquery更改边距而不导致此错误?
Here's an excerpt from my code: 这是我的代码的摘录:
JS : JS :
$(".settingslist").click(function() {
$(".containcontacts,.containtodolist").css({
display: "none"
});
$(".gChange, .aChange, .yChange, .fChange,.speedChange, .bgChange, .simple, .gClick, .aClick, .yClick, .fClick,.speedSave, #Btn, .gSave, .aSave, .ySave, .fSave ,.bgChange, .fSave,.speedClick,.speedtext,#ImageUrl,.settingstxt,.containweather,#ddbtn").css({
display: "block"
});
$(".gChange, .aChange, .yChange, .fChange,.speedChange, .bgChange, .simple").css({
margin-left:"60px"
});
});
For reference, the full program can be found here (I didn't create a snippet, because it is not an isolated part of the code): https://codepen.io/Refath/pen/rdZwxE 作为参考,可以在此处找到完整程序(我没有创建代码段,因为它不是代码的孤立部分): https : //codepen.io/Refath/pen/rdZwxE
Basically, add double quotation marks on margin-left or use marginLeft
instead. 基本上,在margin-left处添加双引号或使用
marginLeft
代替。
Here is jQuery API 's explanation: 这是jQuery API的说明:
...jQuery can equally interpret the CSS and DOM formatting of multiple-word properties.
... jQuery可以同等解释多词属性的CSS和DOM格式。 For example, jQuery understands and returns the correct value for both
.css({ "background-color": "#ffe", "border-left": "5px solid #ccc" })
and.css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" })
.例如,jQuery理解并返回
.css({ "background-color": "#ffe", "border-left": "5px solid #ccc" })
和.css({backgroundColor: "#ffe", borderLeft: "5px solid #ccc" })
。 Notice that with the DOM notation, quotation marks around the property names are optional, but with CSS notation they're required due to the hyphen in the name.请注意,对于DOM表示法,属性名称周围的引号是可选的,但对于CSS表示法,由于名称中的连字符,因此必须使用引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.