2

我有以下代码:

jQuery

$("document").ready(function(){
    var imglink;
    imglink = 'url("http://poweruser.aeiou.pt/wp-content/uploads/2012/12/google.jpg")';
    $('#trick_img').css('content',imglink);

    $(document).on("click","change",function(){
        imglink = 'url("http://poweruser.aeiou.pt/wp-content/uploads/2012/12/Google-Gmail.jpg")';
        $('#trick_img').css('content',imglink);
    });

});​

HTML

<image id="trick_img" draggable="false"/><br/>
<button id="change">Change image</button>​

CSS

img#trick_img { margin:10px; }

测试链接 http://jsfiddle.net/Y5jA9/

我的问题是:如何改变屏幕上的图像?

4

3 回答 3

3

这一行:

$(document).on("click","change",function(){

应改为:

$(document).on("click","#change",function(){

按 id 引用“更改图像”按钮

于 2013-01-02T02:42:08.350 回答
2
$(document).on("click","#change",function(){
        imglink = 'http://poweruser.aeiou.pt/wp-content/uploads/2012/12/Google-Gmail.jpg';
        $('#trick_img').attr('src',imglink);
    });
于 2013-01-02T02:43:17.133 回答
0
 $(document).on("click","#change",function(){
        var imglink;
        imglink = 'http://poweruser.aeiou.pt/wp-content/uploads/2012/12/Google-Gmail.jpg';
        $('#trick_img').attr('src',imglink);
    });

尝试这个

http://jsfiddle.net/Y5jA9/3/

于 2013-01-02T03:08:21.807 回答