Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.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
如何延迟an的加载<;a>;javascript/html中的标记_Javascript_Html - Fatal编程技术网

如何延迟an的加载<;a>;javascript/html中的标记

如何延迟an的加载<;a>;javascript/html中的标记,javascript,html,Javascript,Html,我有一个问题,我们显示的某些链接与页面本身的其余部分分离,因此当你打开页面时,链接会立即显示出来,但页面加载需要2-3秒,我试图延迟链接(在本例中是google),以便在页面加载后几秒钟显示出来。 我快到了吗 <!DOCTYPE html> <html> <head> <title>Delay export link</title> <script type="text/javascript"> fu

我有一个问题,我们显示的某些链接与页面本身的其余部分分离,因此当你打开页面时,链接会立即显示出来,但页面加载需要2-3秒,我试图延迟链接(在本例中是google),以便在页面加载后几秒钟显示出来。 我快到了吗

<!DOCTYPE html>
<html>

  <head>
    <title>Delay export link</title>
    <script type="text/javascript">

function myFunction() {
    myVar = setTimeout(show(), 2000);
}

function show() {
    document.getElementById("Link").style.display = "inline";
}

function exportSrc() {
   var scrt_var = "www.google.com;
  document.getElementById("Link").setAttribute("href",scrt_var);  
} 

    </script>
  </head>

   <style>
     #Link{display:none;}
    </style>

 <body window.onLoad="myFunction();">
   <a id="Link" onclick="exportSrc();" target='_blank'>
   <img src="http://i57.tinypic.com/mkw779.png">
     </a>
    </div>
  </body>

</html>

延迟导出链接
函数myFunction(){
myVar=setTimeout(show(),2000);
}
函数show(){
document.getElementById(“Link”).style.display=“inline”;
}
函数exportSrc(){
var scrt_var=“www.google.com;
document.getElementById(“Link”).setAttribute(“href”,scrt\u var);
} 
#链接{显示:无;}
试试看



与window.onLoad不同,您的页面中出现了一些错误,这些错误导致此功能无法正常工作:

通常,当某些东西不工作时,首先要检查的是浏览器控制台(按F12键)并查找错误。这不会解决逻辑问题,但会使您处于开始调试的良好状态

  • exportSrc
    中缺少
    语法错误-这将显示在浏览器控制台中
  • 正文中的
    load
    属性不正确。您应该只使用
    onload=“myFunction()”
  • 您的
    setTimeout
    正在调用
    show
    ,而不是引用它。卸下
    ()
    s
  • 标记放入
  • 您有一个额外的
    标记
  • 这应该更好地发挥作用:

    <!DOCTYPE html>
    <html>
    
        <head>
            <title>Delay export link</title>
            <style>
                #Link{display:none;}
            </style>
            <script type="text/javascript">
    
            function myFunction() {
                myVar = setTimeout(show, 2000);
            }
    
            function show() {
                document.getElementById("Link").style.display = "inline";
            }
    
            function exportSrc() {
                var scrt_var = "www.google.com";
                document.getElementById("Link").setAttribute("href",scrt_var);  
            } 
    
            </script>
        </head>
    
    
        <body onload="myFunction();">
            <a id="Link" onclick="exportSrc();" target='_blank'>
                <img src="http://i57.tinypic.com/mkw779.png">
            </a>
        </body>
    
    </html>
    
    
    延迟导出链接
    #链接{显示:无;}
    函数myFunction(){
    myVar=setTimeout(show,2000);
    }
    函数show(){
    document.getElementById(“Link”).style.display=“inline”;
    }
    函数exportSrc(){
    var scrt_var=“www.google.com”;
    document.getElementById(“Link”).setAttribute(“href”,scrt\u var);
    } 
    
    foo
    foo()
    之间有一个重要的区别。我应该在这里放哪一个呢?虽然内联事件处理程序是从1990年代开始的,但如果您使用正确的处理程序,它们应该可以工作,这确实是
    onload
    ,而不是
    window.onload
    。如果它对您不起作用,您必须以错误的方式进行测试。链接根本不显示,在我测试的另一种模式中,我收到一个错误,说“意外令牌非法”。这个答案并不能解决您的整个问题,它告诉您没有名为
    window.onLoad
    的HTML属性。请不要期望这个网站只是产生你可以盲目复制和粘贴的代码。我知道,我整天都在挖掘这些命令,我没有javascript方面的经验,但这是我能做的最好的了。我想我快到了,但是少了点东西。。希望能在这里找到,但我想我必须继续搜索谢谢!!这太棒了
    <!DOCTYPE html>
    <html>
    
        <head>
            <title>Delay export link</title>
            <style>
                #Link{display:none;}
            </style>
            <script type="text/javascript">
    
            function myFunction() {
                myVar = setTimeout(show, 2000);
            }
    
            function show() {
                document.getElementById("Link").style.display = "inline";
            }
    
            function exportSrc() {
                var scrt_var = "www.google.com";
                document.getElementById("Link").setAttribute("href",scrt_var);  
            } 
    
            </script>
        </head>
    
    
        <body onload="myFunction();">
            <a id="Link" onclick="exportSrc();" target='_blank'>
                <img src="http://i57.tinypic.com/mkw779.png">
            </a>
        </body>
    
    </html>