inputタグやbuttonタグにonclickを使ってリンクを設定する方法

リンクを設定する方法は

<a href="index.html">遷移</a>

だが、今回紹介するのは、inputタグやbuttonタグに設定する方法だ。

inputタグ

<input type="button" onclick="location.href='index.html'" value="遷移">


<!-- 直前のページに戻る -->
<input type="button" onclick="history.back()" value="戻る">

input type submitには設定できないので注意

buttonタグ

<button onclick="location.href='index.html'">遷移</button>


<!-- 直前のページに戻る -->
<button onclick="history.back()">戻る</button>
(Visited 1,274 times, 1 visits today)

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です