javascript - jquery 麻烦——将字符串添加到动态命名的元素

标签 javascript jquery html css

嘿伙计们,我试图在通过 jQuery 调用 href 'rel' 属性后将字符串 'url("") ' 添加到它周围。我只是不知道正确的语法。这是我所拥有的。我试图将 url("") 放在 rel 标签内,但没有成功。

如有任何帮助,我们将不胜感激。

$(function() {
    $('#list li a').hover( function(){
        $("#meow").css( "background", $(this).attr('rel') );
    }); 
});

最佳答案

像这样(感谢@nnnnnn):

var thisRel = $(this).attr('rel'),
theURL = 'url("' + thisRel + '")';
$("#meow").css( "background", theURL );

关于javascript - jquery 麻烦——将字符串添加到动态命名的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9028072/

相关文章:

javascript - 将数据参数从 parent 传递给 child

html - 无法居中图像

html - 在 Bootstrap 网格中将矩形缩略图设为正方形以获得大屏幕尺寸

html - CSS云动画问题

javascript - 如何从 Javascript 函数中调用 PL/SQL 变量?

javascript - 在 tsconfig 中禁用 @types/node

javascript - jquery 窗口加载并调整大小未运行

JQuery选择器问题

javascript - 获取带有 cookie 的 Accordion 以记住链接状态

javascript - 灯箱在 IE 8 中不工作