javascript - 如何更改内容 :url in jquery? 的 css 属性

标签 javascript jquery html css

我有一个问题:

<div id="arrow"></div>
<div id="p0" style="content: url(images/cerchioSelezionato.png)"></div>
<div id="p1" style="content: url(images/cerchio.png)"></div>

我的目标是:当我点击#arrow 元素时,我希望#p0 的图像变成 cerchio,反之亦然,为此我在 jQuery 中编写了这段代码:

$(document).ready(function(){
    $("#arrow").click(function(){
       $("#p1").attr({content:url(images/cerchioSelezionato.png)});
       $("#p0").attr({content:url(images/cerchio.png)});
    }
}

当我在 chrome 中点击箭头时,控制台会给我这个错误:

Uncaught ReferenceError: url is not defined 
slider_script.js:12(anonymous function)     slider_script.js:12m.event.dispatch jquery-1.11.1.min.js:3r.handle

最佳答案

尝试...

$(document).ready(function(){
    $("#arrow").click(function(){
       $("#p1").attr({style: "content:url(images/cerchioSelezionato.png)" });
       $("#p0").attr({style: "content:url(images/cerchio.png)" });
    }
}

您正在更改 Style 属性,但更改了 content 属性。

关于javascript - 如何更改内容 :url in jquery? 的 css 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27318570/

相关文章:

javascript - 在 Windows 8 Javascript 应用程序中使用 SQLite3

javascript - 使用 jQuery 查找事件对象

javascript - 如何高效使用jquery和javascript?

javascript - 确保 Accordion 选项卡是独立的

javascript - 我怎样才能禁用事件监听器?或者有一个停止按钮来实现它的功能?

php - 浏览器之外的灯箱

javascript - 水平滚动一个div到某个类名

javascript - 如何在 IE8 中测试对象文字

javascript - NodeJS Http 发布 JSON 数据

css - 导致DIV填满页面?