有没有办法得到一个 <button>元素链接到一个位置而不将其包装在 <a href ... 标签中? [英] Is there a way to get a <button> element to link to a location without wrapping it in an <a href ... tag?
本文介绍了有没有办法得到一个 <button>元素链接到一个位置而不将其包装在 <a href ... 标签中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道是否有办法让 HTML <button>
元素链接到一个位置,而无需将其包装在 <a href...
标签?
Just wondering if there is a way to get a HTML <button>
element to link to a location without wrapping it in an <a href...
tag?
按钮当前看起来像:
<button>Visit Page Now</button>
我希望不拥有的:
<a href="link.html"><button>Visit Page Now</button></a>
该按钮未在表单中使用,因此 不是一个选项.我只是想知道是否有一种方法可以链接这个特定元素而无需将其包装在
<a href
标签中.
The button is not being used within a form so <input type="button">
is not an option. I am just curious to see if there is a way to link this particular element without needing to wrap it in an <a href
tag.
期待听到一些选择/意见.
Looking forward to hearing some options/opinions.
推荐答案
内联 Javascript:
Inline Javascript:
<button onclick="window.location='http://www.example.com';">Visit Page Now</button>
在 Javascript 中定义一个函数:
Defining a function in Javascript:
<script>
function visitPage(){
window.location='http://www.example.com';
}
</script>
<button onclick="visitPage();">Visit Page Now</button>
或在 Jquery 中
or in Jquery
<button id="some_id">Visit Page Now</button>
$('#some_id').click(function() {
window.location='http://www.example.com';
});
这篇关于有没有办法得到一个 <button>元素链接到一个位置而不将其包装在 <a href ... 标签中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文