我有一个按钮,当您单击该按钮时,它将带您到我的一个子站点。
该按钮是a
标记的子元素。有更好的方法吗?
<a target='_blank' href='example.com/sub-site.html'>
<button name='link' style="cursor:pointer" class='example-style' value='example.com/sub-site'
title='Example Title>Example</button></a>
如果可能的话,我宁愿不要使用form
标签。
谢谢!
答案 0 :(得分:0)
使用JavaScript进行重定向。 这里显示一个示例:
<button id="button1">Example</button>
<script>
document.getElementById('button1').onclick = function() {
window.location.href = "example.com/sub-site";
}
</script>
答案 1 :(得分:0)
您可以直接在href
标签内添加<button>
:
<button onclick="window.location.href = 'example.com/sub-site.html';">Example</button>
我希望这会有所帮助!
答案 2 :(得分:0)
如果您的问题是更好的“ a href ...”或“ button ...”:我会告诉您,因为重定向是显式的,所以对我来说是“ a href”。