簡體   English   中英

為什么更改圖片來源,執行我的內聯javascript

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM