我有一个 javascript,它显示来自样式和 css 的图像。
<script type="text/javascript">
$(function () {
$("div[style]").click(function() {
$("#full-wrap-new").css("background-image", $(this).css("background-image"));
});
});
</script>
<div id="colors">
<div style="background-image:url(/images/style/whatcan.jpg); width:200px; height:150px; float: left; margin:4px"></div>
<div style="background-image:url(/images/art/art.jpg); width:200px; height:150px; float: left; margin:4px"></div>
<div style="background-image:url(/images/beauty/beauty.jpg); width:200px; height:150px; float: left; margin:4px"></div>
<div style="background-image:url(/images/careers/career.jpg); width:200px; height:150px; float: left; margin:4px"></div>
</div>
我想更改脚本以使用 img 而不是 css 如何更改以下脚本行。
$("#full-wrap-new").css("background-image", $(this).css("background-image"));
这是我到目前为止所拥有的,但我不知道如何将其更改为 img
<script type="text/javascript">
$(function () {
$("div.ri").click(function() {
$("#full-wrap-new").css("background-image", $(this).css("background-image"));
});
});
</script>
<div id="colors">
<div class="ri"><img src="/images/style/whatcan.jpg"/></div>
<div class="ri"><img src="/images/art/art.jpg"/></div>
<div class="ri"><img src="/images/beauty/beauty.jpg"/></div>
<div class="ri"><img src="/images/careers/career.jpg"/></div>
</div>
<div id="full-wrap-new"></div>