所以我有下面的代码,非常适合我!
$("#custom_logo").css("marginLeft", $(".rt-container:first").css("marginLeft"));
但我的问题是,我希望能够在边距上再添加 15 个像素,但下面的代码根本不起作用。
$("#custom_logo").css("marginLeft", $(".rt-container:first").css("marginLeft")+15);
我认为就是这样,因为输出将类似于“260px15”而不是“275px”,这正是我的目标。我想知道是否有一种方法可以做到这一点,只是我忽略了?
最佳答案
以下内容适合您!
$("#custom_logo").css("marginLeft", parseInt($(".rt-container:first").css("marginLeft")) +15);
parseInt() 可以去掉字符串末尾的 'px' 并转换为整数。
关于javascript - Jquery - 添加动态变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23868376/