我如何做一个带有重定向到 URL 的 bobbly-button?

How can i do a bobbly-button with redirect to URL?

我试图让按钮在被点击后重定向到 http://www.hub.test.ru 500 毫秒,但它不是很有效。

我该如何解决?

这是我的代码:

<div class="center">
<button class="bubbly-button" onclick="setTimeout("location.href = 'http://www.hub.test.ru';", 500);">Hub</button>
</div>

setTimeout 接受函数和延迟。 “"location.href = 'http://www.hub.test.ru';"”不是函数。

相反,将其包装在箭头函数中。您的 JS 应如下所示:

setTimeout(()=>{location.href = 'http://www.hub.test.ru'}, 500);

结果:

<div class="center">
  <button class="bubbly-button" onclick="setTimeout(()=>{location.href = 'http://www.hub.test.ru'}, 500);">Hub</button>
</div>

但是,您不应使用内联事件处理程序。我建议使用 addEventListener:

document.querySelector('.bubbly-button').addEventListener('click', ()=>{
  setTimeout(()=>{location.href = 'http://www.hub.test.ru'}, 500);
})
<div class="center">
  <button class="bubbly-button">Hub</button>
</div>