[英]jQuery chaining
I don't think I'm correctly understanding jQuery chaining. 我不认为我正确理解jQuery链接。 I'm looping through an array and trying to add div elements to my wrapper CSS class with each div element having a class of 'click' and custom css top and left attributes, like this:
我循环遍历数组并尝试将div元素添加到我的包装CSS类中,每个div元素都有一个'click'类和自定义css top和left属性,如下所示:
$('<div></div>').appendTo('.wrapper').addClass('click').css('top',click.y).css('left'.click.x);
But it fails to work as expected - it adds one div element, sets my .wrapper div's class to 'click' and then stops. 但它无法按预期工作 - 它添加了一个div元素,将我的.wrapper div的类设置为'click'然后停止。
If I remove 如果我删除
.css('top',click.y).css('left'.click.x);
it works as expected - adding new div elements to the wrapper div. 它按预期工作 - 向包装器div添加新的div元素。
How can i get this to work properly? 我怎样才能让它正常工作? Thanks
谢谢
Use a JSON object for .css
. 使用
.css
的JSON对象。
.css({
'left' : click.x,
'top' : click.y
});
try this 试试这个
$('<div>/div>').appendTo('.wrapper').addClass('click').css({
'top': click.y,
'left': click.x
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.