![](/img/trans.png)
[英]A button on being clicked should open a webpage in an iframe named destination
[英]open a webpage with button clicked
我正在用HTML編寫代碼,它有2個按鈕,例如a
和b
。 我想在URL中傳遞一些東西來觸發按鈕。 我知道我們該如何處理div。
<div class="a"> <a name="a" /> This is Div A </div> <div class="b"> <a name="b" /> This is Div B </div>
並且我可以直接傳遞myURL.com#a
/ myURL.com/#b
轉到該div。 但是我想知道是否可以使用按鈕來做到這一點。
謝謝
是的,您可以使用一些JavaScript來做到這一點:
<button onclick="window.location='#a';">Go to Div A</button>
如果希望顯示按鈕A 或按鈕B之一,則可以使用以下命令:
的CSS
.button {
display: none;
}
.button:target {
display: block
}
的HTML
<!-- link in the same page -->
<a href="#A">go to button 1</a><br>
<a href="#B">go to button 2</a><br>
<!-- link from external page -->
<a href="your_url.com/#A">go to button A</a><br>
<a href="your_url.com/#B">go to button B</a><br>
<!-- buttons will only be visable when linked to -->
<a class="button" id="A"><input type="button" value="button A"></a>
<a class="button" id="B"><input type="button" value="button B"></a>
如果您只想跳到該按鈕,則回答您自己的問題。 只需將<div id="A">
包裹在按鈕周圍即可。
首先將id
屬性添加到div中。 例如; <div class="b" id="part-b">
然后只需鏈接到mypage.html#part-b
,例如; <a href="mypage.html#part-b>Go to part b</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.