0
A
回答
0
比方说,你有下面的代码...
<div id='container'>
<img src='some location'>
</div>
您可以用下面的jQuery代码改变形象...
function change_image(){
$("#container").html("<img src='some other image location'>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
让我知道它是否有效。
0
因为你说你是jQuery的新手,所以我在注释代码时特别注意。你没有真正指定背景图像应该如何设置,所以我在缩略图上使用了一个点击事件。
代码:
// before doing our magic with jQuery,
// we must wait for the dom to be ready to be manipulated
$(document).ready(function() {
// listen for a click on any img inside the .images
$('.images img').on('click', function() {
// inside the event handlers callback, THIS refers to the img that was clicked
// here we save the src property of the clicked img to a variable
var imgSrc = $(this).prop('src');
changeBackgroundImg(imgSrc);
});
});
function changeBackgroundImg(imgSrc) {
// we can set any css property to an element with jQuerys .css()
$('body').css('background-image', 'url(' + imgSrc + ')');
}
这里有一个demo。
链接到相关的文档代码:
相关问题
- 1. jquery更改div背景图片点击
- 2. 如何使用jQuery更改背景图片“点击”?
- 3. 按钮点击更改背景图片
- 4. 在点击javascript更改背景图片
- 5. 点击更改背景图片
- 6. 点击jquery更改背景
- 7. 用jQuery和html5点击更改背景图片
- 8. 使用模板更改悬停/点击按钮背景图片
- 9. 当点击图片时更改背景图片
- 10. 用jquery更改背景图片wbkit
- 11. 用jquery更改背景图片
- 12. 点击使用jquery更改背景图像
- 13. jquery更改点击图片
- 14. 背景图片点击
- 15. jQuery Parent UL背景更改点击
- 16. jQuery每次点击更改背景
- 17. UIButton背景更改点击
- 18. 使用jQuery改变背景图片
- 19. 更改背景图片 - jQuery UI的
- 20. jquery - toggleClass不更改背景图片
- 21. 点击时更改背景图像 - Android
- 22. UIButton背景图像点击更改
- 23. jquery - 背景图像点击
- 24. 更改背景图片
- 25. 更改背景图片div
- 26. 更改UINavigationBar背景图片
- 27. MapKit:更改背景图片?
- 28. 更改背景图片
- 29. 用jQuery点击更改图片
- 30. 与点击更改CSS背景图片 - while循环不工作
我清理你的问题有点。你试过什么了?任何我们可以离开的地方? – Celeo 2015-03-30 22:14:04