gpt4 book ai didi

jquery - 有没有办法将变量添加到 jquery css 方法?

转载 作者:太空宇宙 更新时间:2023-11-03 23:21:44 24 4
gpt4 key购买 nike

有没有办法用可变宽度替换下面代码中的 255px?

var width = $(".input-textbox").width();

$("#txtTryContactMob").css('background', '#fff url(\"/img/erroricon.png\") 255px center no-repeat');

我已经阅读了一些相关内容,但我不想使用 LESS css。

提前致谢。

最佳答案

您还可以通过专门针对 background-size 样式将宽度与其余 CSS 样式分开:

 var width = $(".input-textbox").width();
$("#txtTryContactMob").css('background', '#fff url("/img/erroricon.png") 255px center no-repeat')
.css('background-size', width);

注意事项:

  • 在使用单个 CSS 属性时不需要添加 px
  • 您不需要转义单引号字符串中的双引号

关于jquery - 有没有办法将变量添加到 jquery css 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28411917/

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