jquery图像更改不起作用

时间:2012-11-17 20:27:26

标签: javascript jquery

以下代码应该可以工作,但我似乎无法找到问题,为什么它不起作用,我用谷歌浏览器测试它

<html>
    <head>
        <script type="text/javascript" src="js/jquery_1.7.1_min.js"></script>
        <script type="text/javascript">
            $('#unos').click(function() {
                $("#tre").attr('src', '/012/11/image2.jpg');
            });
        </script>
    </head>

    <body>
        <img id="tre" class="aligncenter" title="images" src="/012/11/image1.jpg" alt="" width="940" height="207" />
        <input id="unos" type="submit" name="change_src" value="change image" />
    </body>
</html>

1 个答案:

答案 0 :(得分:2)

<html>
    <head>
        <script type="text/javascript" src="js/jquery_1.7.1_min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#unos').click(function() {
                    $("#tre").attr('src', '/012/11/image2.jpg');
                });
            });
        </script>
    </head>

    <body>
        <img id="tre" class="aligncenter" title="images" src="/012/11/image1.jpg" alt="" width="940" height="207" />
        <input id="unos" type="submit" name="change_src" value="change image" />
    </body>
</html>