简体   繁体   English

试图使用链接延迟,但我尝试的任何代码都无法正常工作

[英]Trying to use a link delay, but any code I try isn't working

I am trying to create a little .25 second link delay along with a zooming property, to add an artistic flare to my site. 我试图创建一个.25秒链接延迟以及缩放属性,为我的网站添加艺术耀斑。 In order to see the zoom, I need a small link delay. 为了看到缩放,我需要一个小的链接延迟。 I have been trying code that I have found online but for some reason the delays just don't work. 我一直在尝试在网上找到的代码,但由于某些原因,延迟不起作用。

Here is an example of one of the code snippets I have tried. 以下是我尝试过的代码片段之一的示例。

<li><a href="#" onclick="setTimeout(window.document.location='http://******.net/html/****.html',250);">CONTACT</a></li>

Any ideas as to why it isn't working? 关于它为什么不起作用的任何想法? Keep in mind that I only want a few links on the page to have this delay so a block of JavaScript or jQuery that assigns all a href links with a delay is not ideal. 请记住,我只希望页面上的一些链接具有此延迟,因此一个JavaScript或jQuery块为所有a href链接分配延迟并不理想。

This is a Classic-ASP project using Vb-script. 这是一个使用Vb脚本的Classic-ASP项目。

<a onclick="return createTimedLink(this, myFunction, 2000);" href="http://******.net/html/****.html">Link</a>

Then have this 然后有这个

function createTimedLink(element, callback, timeout){
  setTimeout( function(){callback(element);}, timeout);
  return false;
}

function myFunction(element) { 
/* Block of code, with no 'return false'. */
  window.location = element.href;
 }

Source: https://stackoverflow.com/a/6609164/5393628 资料来源: https//stackoverflow.com/a/6609164/5393628

setTimeout需要一个函数

<li><a href="#" onclick="setTimeout(function() { window.document.location='http://******.net/html/****.html'; },250);">CONTACT</a></li>

Isn't a 0.25 second delay too short to be noticed? 0.25秒的延迟是不是太短而不被注意到? However, this would work 但是,这会奏效

 <ul> <li><a href="#" onclick="goto('http://google.com')">CONTACT</a></li> <script> function goto(link) { setTimeout(function () { document.location = link; }, 250); } </script> </ul> 

For each link you want to place the delay on, you could use the onclick="goto(link)" attribute or use href="javascript:goto(link)" 对于您想要延迟的每个链接,您可以使用onclick =“goto(link)”属性或使用href =“javascript:goto(link)”

setTimeout should recieve a function as a first parameter. setTimeout应该将函数作为第一个参数接收。 So you have to change your onclick handler to setTimeout(function() { window.document.location='....'; }, 250); 因此,您必须将onclick处理程序更改为setTimeout(function() { window.document.location='....'; }, 250);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我尝试使用IFFE时,为什么这段代码不起作用? - Why isn't this code working when i try to use IFFE 所以我正在尝试使用 Math.cbrt 并且我的代码没有按预期工作 - So I'm trying to use Math.cbrt and my code isn't working as expected 我试图找出两个 arrays 之间的区别,但我的代码对 0 不起作用有什么建议吗? - I'm trying to find the difference between two arrays but my code isn't working for 0s any advice? 当我使用 fetch my.then 代码不起作用 - When I use fetch my .then code isn't working 延迟()不适用于焦点() - Delay() isn't working on focus() 我的代码中是否有任何泄漏,只有 1 个案例不起作用我不知道为什么? - Is there any leak in my code, Only 1 case isn't working I don't know why? 我正在尝试将数字提高到其连续的功效,而我的代码不起作用 - I'm trying to raise numbers to their consecutive powers and my code isn't working 我试图了解为什么此JS代码段无法正常工作,可以使用一些可添加到WP中的指南 - I am trying to understand why this JS snippet isn't working, could use some guidance adding to WP 我正在尝试使用简单的网络摄像头捕获上传,上传不起作用? - I'm trying to use a simple webcam capture upload, upload isn't working? 尝试学习addEventListener并且我的代码不起作用 - Trying to learn addEventListener and my code isn't working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM