我有一个问题:
<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/