javascript函数在完成后重新加载页面

javascript函数在完成后重新加载页面,javascript,jquery,html,reload,Javascript,Jquery,Html,Reload,我有一个简单的javascript程序,可以运行图像的onclick 但是,每当我单击图像时,页面都会重新加载 经过大量调试后,我发现页面直到脚本完成后才重新加载 代码中有几个设置超时,但我注意到页面正在立即重新加载。我甚至将这些超时更改为15000毫秒,但它仍然会立即重新加载 如果有什么不同的话,我正在使用jquery 我还希望每次单击该程序时都能得到不同的结果,以便每次单击时都会运行不同的脚本,并按特定顺序更改一些文本。为此,我将每个脚本中图像的onclick属性更改为下一个脚本的名称,以便

我有一个简单的javascript程序,可以运行图像的onclick

但是,每当我单击图像时,页面都会重新加载

经过大量调试后,我发现页面直到脚本完成后才重新加载

代码中有几个设置超时,但我注意到页面正在立即重新加载。我甚至将这些超时更改为15000毫秒,但它仍然会立即重新加载

如果有什么不同的话,我正在使用jquery

我还希望每次单击该程序时都能得到不同的结果,以便每次单击时都会运行不同的脚本,并按特定顺序更改一些文本。为此,我将每个脚本中图像的onclick属性更改为下一个脚本的名称,以便脚本一将onclick切换为脚本二,依此类推。我在这些开关上设置了一个超时,这样一次单击就不会在每个脚本中都出现。脚本2没有运行,所以有很多工作要做

我的代码:

function getSounds() {
    console.log("script. initiated");
    $("#soundwebGetSoundDirections").html("Now, Wait until the file is done downloading and click below again.");
    console.log("new message");
    $("#soundwebGetSoundA").attr('href',"");
    console.log("href eliminated");
    setTimeout($("#soundwebGetSoundImg").attr('onclick','findFile()'),2000); 
    console.log("onclick to findFile()");

}

function findFile(){
    console.log("FINDFILE")
    $("#soundwebGetSoundDirections").html("Find the file(it's probably in your downloads), copy the path of the file (usually at the top of the file explorer) and paste in it the box below.  Then, make sure there is a '/' at the end of the path and type 'Linkiness.txt' (case sensitive, without quotes) at the end.  Once you have all that stuff typed, click the icon again.");
    console.log("FIND IT, DARN IT!!");
    $("#soundwebGetSoundPathInput").css("opacity",1);
    console.log("diving into reader");
    setTimeout($("#soundwebGetSoundImg").attr('onclick','readFile()'),1000); 
}
function readFile(){
    console.log("loading...");
    $("#soundwebGetSoundDirections").html("loading...");
    if(document.getElementById("soundwebGetSoundPathInput").value.length == 0){
        setTimeout($("#soundwebGetSoundDirections").html("Please fill in Path!"),1000);
        setTimeout(findFile(),2000);
    }

}
以及链接到的HTML

<a id = "soundwebGetSoundA" href = "https://docs.google.com/feeds/download/documents/export/Export?id=1ynhHZihlL241FNZEar6ibzEdhHcWJ1qXKaxMUKM-DpE&exportFormat=txt">
                    <img onclick = "getSounds();" class = "soundwebImgResize" src = "https://cdn3.iconfinder.com/data/icons/glypho-music-and-sound/64/music-note-sound-circle-512.png" id = "soundwebGetSoundImg"/>
                </a>

谢谢你的帮助,
Lucas N.

您没有正确使用
setTimeout
。您应该传入函数而不是语句。所以,比如说

setTimeout($("#soundwebGetSoundDirections").html("Please fill in Path!"),1000);
setTimeout(findFile(),2000);
你应该使用

setTimeout(function () { $("#soundwebGetSoundDirections").html("Please fill in Path!") },1000);
setTimeout(findFile,2000);
我认为设置
onclick
属性也是如此,但我从未尝试过像这样动态更改
onclick
属性


因为您已经在使用jQuery,所以可以尝试使用
.on('click'…
.off)('click'…
如果您当前的设置不起作用。

如果您不想单击图像以使锚定标记加载href,那么请将图像标记移到锚定标记之外。

您已经将图像放在锚定标记中并带有href。您期望得到什么?我不确定。我不太擅长网站建设。我应该填充人力资源吗ef在图像上?你想让环绕图像的链接作为链接使用吗?我不清楚它为什么会出现。该链接是我只想在你第一次单击它时下载的。嗯……我尝试了所有这些,但没有任何更改。它仍在重新加载。当你删除
href
(用于测试目的)时会发生什么情况这就是问题所在,谢谢。