gpt4 book ai didi

javascript - 将保存在变量中的像素数量添加到 jQuery 中的 css 属性

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:08 25 4
gpt4 key购买 nike

我想将存储在我的变量“x”中的一定数量的像素添加到 jQuery 中的 css 属性。

我知道从 jQuery 1.6 开始你可以很容易地使用像这样的东西:

$(this).css({top: "+=150"});

但是当我使用变量而不是 150 时它不起作用,因为变量必须用引号括起来。

$(this).css({top: "+= x"});

最佳答案

请试试这个

$(this).css({top: "+= "+ x +"px"}); 

而不是你的代码

关于javascript - 将保存在变量中的像素数量添加到 jQuery 中的 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46930280/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com