使用任何其他方法而不是<a>链接

Use any other method insted of <a> links

本文关键字:链接 任何 其他 方法      更新时间:2023-09-26

嗨,我需要有一个方法来做链接的相同使用。我在我的网站上有按钮。(css样式和颜色按钮)。我需要有一个方法来加载一个页面时,按钮单击。举个例子:当有人点击红色按钮时,指令页面应该被加载。谁能建议我一个js或jquery函数来做到这一点?

谢谢!

试试这个JS:

location.href = 'http://www.google.com/' //goes to www.google.com
那么,你的完整代码应该是这样的:
var btn = document.getElementById('your_button_id');
btn.onclick = function() {
    location.href = 'http://www.google.com/' //insert your URL here
}

当然,你也可以用a标签来代替:

<a href='http://www.google.com/'><button type='button'>Click Me</button></a>
这个方法:

  • 是更SEO和访问友好的
  • 告诉更多关于按钮实际应该做什么的信息
  • 激活某些浏览器对链接的行为,比如
    • 显示它们在状态栏中的位置
    • 特别强调
  • 可以在禁用JavaScript的情况下工作

所以这是一个更好的主意

您可以试试下面的代码

<input name="" type="button" value="button" onclick="window.location='www.yourdomain.php'"/>

相关文章: