html改变事件的javascript

来源:百度知道 编辑:UC知道 时间:2024/06/21 03:43:05
网页中有一个图片,这个图片有onmouseover和onmouseout方法,

页面中还有一个按钮,点击该按钮就停止图片的onmouseover事件,再次点击按钮就恢复onmouseover。

求 代码示例。

谢谢!!!
首先对你的回答表示感谢!!!

一个问题:对于这样的img.onmouseover=mouseOver; 使用以前没有用过,我想了解一下,如果mouseOver这样方法带有参数的话,可否还这样写,如果可以的话,我要修改参数怎么做(多个地方调用同一个方法)。如果不可以的话,有替代的写法吗??

谢谢

简单的:
img.onmouseover = new function() { mouseOver(参数) };
复杂的:
Function.prototype.bind = function(o) {
var _this = this,
tmp = function() {
return _this.apply(o, arguments);
};
return tmp;
}
function mouseOver(参数) {
this.参数 = 参数;
this.doOver = function() {
alert(this.参数);
}
}
var o = new mouseOver(参数);
img.onmouseover = o.doOver.bind(o);

<html>
<body>
<script>
var img=document.createElement("img");
img.src="img/1.jpg";
img.onmouseover=mouseOver;
img.onmouseout=mouseOut;
var button=document.createElement("input");
button.type="button";
button.value="s";
button.onclick=buttonClick;

document.body.appendChild(img);
document.body.appendChild(button);

function mouseOver(){
alert("mouseOver");
}

f