结合onmouseover事件和<a>标签
Incorporating onmouseover event and <a> tag
这是包含onmouseover事件和标签的代码:
您可以将image1.src和image2.src更改为您喜欢的任何图像
<!--
if (document.image){
var image1 = new Image();
image1.src = "Dark Swampert.jpg";
var image2 = new Image();
image2.src = "Tulips.jpg";}
function printPage(){
window.print();}
//-->
body{background-color: aquamarine;}
<head><title> Cheater </title></head>
<body>
<p> Move the mouse over the image to see results: </p>
<a href="#" onmouseover="document.myImage.src=image2.src;" onmouseout="document.myImage.src=image1.src;">
<img name="myImage" src="Dark Swampert.jpg" width=120 height=160/>
</a>
<br><input type=button value="Print this Page!" onClick="printPage();"/>
</body>
然而,当你把鼠标移到图像上时,它会显示
未捕获的类型错误:无法读取未定义的属性"src"
代码出了什么问题?提前感谢!!
document.image
未定义。我想你需要document.images
。尽管你的代码真的一团糟。:)
<!--
if (document.images){
var image1 = new Image();
image1.src = "Dark Swampert.jpg";
var image2 = new Image();
image2.src = "Tulips.jpg";}
function printPage(){
window.print();}
//-->
body{background-color: aquamarine;}
<head><title> Cheater </title></head>
<body>
<p> Move the mouse over the image to see results: </p>
<a href="#" onmouseover="document.myImage.src=image2.src;" onmouseout="document.myImage.src=image1.src;">
<img name="myImage" src="Dark Swampert.jpg" width=120 height=160/>
</a>
<br><input type=button value="Print this Page!" onClick="printPage();"/>
</body>
var image1 = new Image();
image1.src = "Dark Swampert.jpg";
var image2 = new Image();
image2.src = "Tulips.jpg";
图像1和图像2必须在全局范围内。
相关文章:
- 在<页眉>标签
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- </脚本>标签放错地方了
- Jquery在点击<a>标签
- Ionic V1.3-标签-带条件的徽章样式<离子选项卡>
- <选择>标签不起作用
- 如何在<嵌入>标签在Plone 4.1中
- 在<script src=“"></脚本>标签
- 使用几个<脚本>标签不会't工作-只调用一个脚本
- 如何在更新面板内部调用/触发javascript函数<触发器>标签
- react-让一个元素返回两个相邻的<tr>标签
- <h1>标签在离子含量元素中不可见
- VS代码:在<脚本>标签
- 在</表单>标签
- Meteor.js:<脚本>标签不't在<身体>
- Highlight.js为每个<代码>标签
- 聚合物-如何从<a>标签
- 当通过<a>标签,它无法正确加载
- HTML上的Webpack JSX错误<来源>标签
- 如何使角度显示为空<p>标签