Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网页中的图像出现一小段时间,然后消失_Javascript_Jquery_Html - Fatal编程技术网

Javascript 网页中的图像出现一小段时间,然后消失

Javascript 网页中的图像出现一小段时间,然后消失,javascript,jquery,html,Javascript,Jquery,Html,我在当前目录中有许多图像文件,例如step_graph0.png、step_graph1.png、step_graph2.png、step_graph3.png等等 我的目标是能够使用一个网页来显示他们一个接一个。我创建了两个链接,next和previous,并向它们添加了onclick方法,以便更改image.src属性。代码如下 <html> <head> <script type="text/javascript"> windo

我在当前目录中有许多图像文件,例如
step_graph0.png、step_graph1.png、step_graph2.png、step_graph3.png
等等

我的目标是能够使用一个网页来显示他们一个接一个。我创建了两个链接,next和previous,并向它们添加了
onclick
方法,以便更改image.src属性。代码如下

<html>
    <head>
    <script type="text/javascript">

    window.onload =function f()  {

    f.me  = f.me || 0;

    //alert(f.me);

    var p =document.getElementById("previous");
    var n =document.getElementById("next");
    var image = document.getElementById("graph");

    alert(f.me);

    p.onclick = function(){
        f.me = f.me|| 0;
        if( f.me >  0 ) f.me--;
        image.src = "step_graph"+(parseInt(f.me) ) + ".png";


        //window.location.reload();
    }

    n.onclick = function(){
        f.me = ++f.me || 0;
        image.src = "step_graph"+(parseInt(f.me) )+".png";


        //window.location.reload();
    }


    }       

    </script>
    </head>
    <body>
        <a id="previous" href="">step_back</a> <a id="next" href="">step_forward</a><br>
        <center>
        <img id="graph" src ="step_graph1.png" ></img></center>
        code<br>
        output<br>

    </body>
</html>

window.onload=函数f(){
f、 me=f.me | | 0;
//警惕(f.me);
var p=document.getElementById(“先前”);
var n=document.getElementById(“下一个”);
var image=document.getElementById(“图形”);
警惕(f.me);
p、 onclick=function(){
f、 me=f.me | | 0;
如果(f.me>0)f.me--;
image.src=“步骤图”+(parseInt(f.me))+“.png”;
//window.location.reload();
}
n、 onclick=function(){
f、 me=++f.me | | 0;
image.src=“步骤图”+(parseInt(f.me))+“.png”;
//window.location.reload();
}
}       

代码
输出
我将此文件保存为index.html,与图像保存在同一目录中。首先,它显示图像。但当我单击“下一步”和“上一步”链接时,它会显示所需的图像,但在毫秒内,它会返回到原始图像。我使用f.me作为静态变量来保存图像文件索引,例如文件名
step_graph0.png、step_graph1.png、step_graph2.png
中的
0、1、2、3

我试了一个小时。我认为这是关于
window.onload
函数重置一切。但这只是一个让我满意的猜测

我希望任何人都能找出代码中的错误,请这样做。

var me=me | | 0;
//警惕(f.me);
var p=document.getElementById(“先前”);
var n=document.getElementById(“下一个”);
var image=document.getElementById(“图形”);
$('previous')。在('click',函数(e){
$('#try').html('prev');
e、 预防默认值();
我=我| | 0;
如果(我>0)我--;
image.src=”http://home.iitk.ac.in/~amitkum/images/“+(parseInt(me))+”.jpg”;
//window.location.reload();
});
n、 onclick=函数(e){
e、 预防默认值();
me=++me | | 0;
image.src=”http://home.iitk.ac.in/~amitkum/images/“+(parseInt(me))+”.jpg”;
//window.location.reload();
}




jk
是否抛出任何错误?应该抛出一个
f
为的错误undefined@charlietfl在哪里可以找到它们(firefox web developer控制台显示没有)?这意味着我只需要一个preventDefault():)。谢谢你,阿米特。它起作用了。实际上,您可以将preventDefault()作为href=“#”删除,但您在未定义f的地方使用了f.me。好吧,这就是原因。我不知道。