图片在文件中

时间:2010-06-04 11:05:22

标签: javascript html

<script type="text/javascript">
    picture1 = new Image;
    picture1.src = "picture/loading.jpg";
    picture2 = new Image;
    picture2.src = "picture/loader.jpg";
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a href="page5.html" onmouseover="document.picture2.src=picture2.src" 
                         onmouseout="document.picture1.src=picture1.src">
       <img name="picture" src="picture/loading.jpg" alt="image" />
    </a>

    </div>
    </form>
</body>

这是我调试时的代码,显示:

 Microsoft JScript runtime error: 'document.picture2' is null or not an object

但我已经将'value.picture2'

赋予了价值

1 个答案:

答案 0 :(得分:1)

全局对象为window而非document。因此,您可能希望使用window.picture2.src代替document.picture2.src

此外,您应该为元素添加唯一的id并使用document.getElementById()引用它们:

<img id="picture1" src="picture/loading.jpg" alt="image" />

...使用:

引用
document.getElementById('picture1');