これが最良の方法です。ボタンを使用してリンクを開くには
<button type="button" onclick="location='permalink.php'">Permalink</button>
<button type="button" href="index.php">Permalink</button>
これが最良の方法です。ボタンを使用してリンクを開くには
<button type="button" onclick="location='permalink.php'">Permalink</button>
<button type="button" href="index.php">Permalink</button>
jquery を使用する場合、次のように 2 番目のボタンを記述できます
<button type="button" id="SecondButton" data-href="index.php">Permalink</button>
次に、いくつかのJavaScriptを追加します。
<script type="text/javascript">
$('#SecondButton').click(function(e) {
e.preventDefault(); e.stopPropagation();
window.location.href = $(e.currentTarget).data().href;
});
</script>
編集 (さらに完成したシナリオ)
<button type="button" id="SecondButton" data-href="index.php" onclick="location='permalink.php'" href="index.php">Permalink</button>
追加の href タグと onclick の両方をその中に挿入します。その後、さまざまなシナリオをテストできます。JavaScript または jquery をサポートしていないデバイスは、モバイルなどの CDN での読み込みに失敗します。
<button type="button" id="SecondButton" data-href="index.php?trackAnalytics=1" onclick="location='permalink.php?trackAnalytics=2'" href="index.php?trackAnalytics=3">Permalink</button>
ブートストラップを使用している場合、これを行うことができます...
<a class="btn btn-default" href="permalink.php">Permalink</a>
最初のスクリプトは機能するはずですが、インライン スクリプトは推奨されません。addEventListener
標準準拠のブラウザーおよびattachEvent
古い IEを使用してイベントをアタッチする方法について読む必要があります。
ボタンは属性を使用しないため、href
2 番目は機能しません。
または、ボタン「スタイル」が目的であり、特に<button>
タグではない場合、次のようなことを行うことができます。
<form method="link" action="permalink.php">
<input type="submit" value="Permalink">
</form>
もう 1 つの考えは、アンカーをボタンのようにスタイルしてから、href 属性を使用できるというものです。