开发者

jquery error: "missing : after property id" (JavaScript object)

I have this code:

$.each(properties, function(i, key) {
   obj.css({'-webkit-开发者_如何学编程border-' + key + '-radius': value+'px', '-moz-border-' + key + '-radius': value+'px', 'border-' + key + '-radius': value+'px'});
});

It's giving the error on the first + key

Can't I create keys like this (with appending data) or am I doing something else wrong?

Thanks, Wesley


Can't I create keys like this (with appending data) or am I doing something else wrong?

Nope, you should be getting a syntax error.

You can construct the object before passing it to the css function:

var styles = {};
styles['-webkit-border-' + key + '-radius'] = value+'px';
styles['-moz-border-' + key + '-radius'] = value+'px';
styles['border-' + key + '-radius'] = value+'px';
obj.css(styles);


try this

$.each(properties, function(i, key) {
   var a = '-webkit-border-' + key + '-radius';
   var b = '-moz-border-' + key + '-radius';
   var c = 'border-' + key + '-radius';
   var z = value+'px';
   obj.css({a : z, b: z, c: z});
});

I think that json don't like "building" its keys and values directly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜