使用href和onclick的链接有什么区别? [英] What's the difference between a link using href and onclick?

查看:53
本文介绍了使用href和onclick的链接有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人.我对编程和语言了解不多,我对 HTML 仅有一些基本知识,所以我希望有人可以帮助我理解以下两行之间的区别:

Everyone. I don't know much about programming and languages, I only have a few basics on HTML, so I hope someone could help me understanding the difference between the following two lines:

<a onclick="window.location.href='http://www.example.com'">Click here</a>

<a href="http://www.example.com">Click here</a>

两者似乎都做同样的事情,但是我不确定在所有情况下这是否都是不正确的,即使用不同的浏览器 HTML / HTML5

Both seem to do the exact same thing, but I'm not sure if this is not true in all cases, i.e. using different browsers, HTML/HTML5, etc.

任何帮助将不胜感激.谢谢.

Any help would be appreciated. Thanks.

推荐答案

以下两行之间的区别

the difference between the following two lines

唯一的区别是您使用JavaScript重定向,而不是内置的浏览器功能.

The only difference is that you are using JavaScript to redirect rather than the built-in browser functionality.

有关链接,请参见 W3C规范

这篇关于使用href和onclick的链接有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆