[英]why changing source of image , execute my inline javascript
嗨,大家好,我刚刚创建了一个网页,该网页使用了这种页面方法
function get_frame() {
//send a request to change image named "1.jpeg" in path of "src/frames/1.jpeg"
PageMethods.GrabFrame(imgw, imgh, t, f);
}
function t() {
//refresh image source to new image and set timer
document.getElementById('dImg').src = "src/frames/1.jpeg?" +
new Date().getTime();
setTimeout(function () { get_desktop(); }, Main.IMGrefresh.value);
}
function f() {
//do nothing
var x = 0;
}
并且还使用了内联javascript和jquery这样的
<script>
$("#cover").mousemove(function (e) {
var parentOffset = $(this).parent().offset();
var relX = e.pageX - parentOffset.left;
var relY = e.pageY - parentOffset.top;
move_mouse(relX, relY);
});
</script>
还有一些像这样的asp.net客户端代码
<div id="dDiv">
<img id="dImg" alt="" src="" />
<div id="cover">
</div>
</div>
内联javascript位于该html代码的末尾
因此move_mouse()
方法必须仅在用户移动鼠标时才能运行,它可以正确移动,但是即使图像刷新时鼠标没有移动也可以移动,我的意思是当用javascript刷新图像时,它也运行move_mouse方法。
这些元素的CSS
#cover {
position:absolute;
top:0px;
left:0px;
text-align:center;
background-color:Black;
height:200px;
width:300px;
border:0px none black;
margin:0px auto 0px auto;
filter: alpha(opacity=1);
-moz-opacity: 0.01;
-khtml-opacity: 0.01;
opacity: 0.01;
}
#dDiv {
position:relative;
text-align:center;
background-color:Black;
height:200px;
width:300px;
border:0px none black;
margin:0px auto 0px auto;
}
#dImg {
background-color:Black;
height:200px;
width:300px;
border:0px none black;
margin:0px 0px 0px 0px;
}
而且他们也在改变javascript
function resize() {
imgh = Main.IMGheight.value;
imgw = Main.IMGwidth.value;
$("#dDiv").css("height", imgh);
$("#dDiv").css("width", imgw);
$("#dImg").css("height", imgh);
$("#dImg").css("width", imgw);
$("#cover").css("height", imgh);
$("#cover").css("width", imgw);
}
啊,我自己又找到了它,只需将鼠标事件移至js函数并将其放在body onload中,因为内联javascript方法保存在catch中,并且此命令=>“ new Date()。getTime();” 使它刷新并获取新方法,因此将触发事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.