为什么改变图像的来源,执行我的内联javascript

why changing source of image , execute my inline javascript

本文关键字:我的 执行 javascript 改变 图像 为什么      更新时间:2023-09-26

我刚刚创建了一个网页,使用pagememethods这样的

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方法。

#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();"使其刷新并获得新方法,因此这会触发事件