我的文档头部指定了一种样式。 我在分区上指定背景图像,但稍后需要在用户点击链接时更改它,但我尝试做的所有事情都拒绝工作。
<style type="text/css"> /*Some CSS*/ .large { background: url('/images/artwork1.jpg') no-repeat; } </style> <div class="large"></div> <img id="main_image" alt="Image"/> <img onclick="javascript:document.getElementById('main_image').src='/images/artwork2.jpg'; $('.large').css({'background-image':'url(/images/artwork2.jpg)';" alt="Change Image"/>我尝试将背景图像从样式中删除,但点击链接并没有改变它。 我试过JavaScript和jQuery。 我能够更改图像,直到我添加到jQuery中。
I have a style specified in the head of my document. I specify the background image on a division but later on a need to change it if the user clicks on a link but everything I've tried to do refuses to work.
<style type="text/css"> /*Some CSS*/ .large { background: url('/images/artwork1.jpg') no-repeat; } </style> <div class="large"></div> <img id="main_image" alt="Image"/> <img onclick="javascript:document.getElementById('main_image').src='/images/artwork2.jpg'; $('.large').css({'background-image':'url(/images/artwork2.jpg)';" alt="Change Image"/>I tried taking the background image out of the style but clicking on a link didn't change it. I've tried JavaScript and jQuery. I was able to change the image until I added in the jQuery.
最满意答案
是的,那是因为你的语法有误。
尝试这个。
javascript:document.getElementById('main_image').src='/images/artwork2.jpg'; $('.large').css('background-image', 'url(/images/artwork2.jpg)');
Yeah, that's because you have error in your syntax.
Try this.
javascript:document.getElementById('main_image').src='/images/artwork2.jpg'; $('.large').css('background-image', 'url(/images/artwork2.jpg)');
更多推荐
发布评论