答えて
はちょうど新しいhref
とhref
を変更し、あなたが行われています。
$('.myLink').click(function() {
$(this).attr("href", this.href + "?param=1");
});
クリック時にwindow.locationを設定するだけで、デフォルトの動作を防ぐにはfalseを返します。
等:クリックすると
<a class="myLink" href='http://www.website.it/'>Link</a>
<script type="text/javascript">
var stringToSend = "";
$('.myLink').click(function() {
window.location.href = this.href + "?param=" + stringToSend;
return false;
});
</script>
、あなたは現在のURLを停止し、他に移動できます。
var stringToSend = "";
$('.myLink').click(function() {
stringToSend="?param=1";
window.location.href = $(this).attr('href') + stringToSend; // navigate to new URL
return false; // abort navigation to URL from <a>
});
また、このようなデフォルト動作を防ぐ必要があります:あなたは正しいです:
var stringToSend = "";
// Use this to actually navigate to the changed Uri
$('.myLink').click(function(event) {
event.preventDefault();
stringToSend = "?param=1";
window.location.href = $(this).attr('href') + stringToSend;
});
// Use this just to change the Href, without navigating to uri
$('.myLink').click(function(event) {
event.preventDefault();
stringToSend = "?param=1";
var newUri = $(this).attr('href') + stringToSend;
$(this).attr("href", newUri);
});
?私は避けたいものです。私は使用しないwindows.location.href ... :) – markzzz
event.preventDefault(); stringToSend = "?param = 1"; var newUri = $(これ).attr( 'href')+ stringToSend; $(これ).attr( 'href'、newUri); – DenisPostu
コードフォーマットは申し訳ありませんが、元のコメント – DenisPostu
- 1. Pythonの要求は、私が<a href="https://example.org" rel="nofollow noreferrer">https://example.org</a>に要求を送信
- 2. 私は<a href="https://omeka.org/" rel="nofollow noreferrer">Omeka</a>の私の元のインスタンスを持つリモートサーバー持って
- 3. の画像は、私はgithubのページに<a href="http://calebbertrand.github.io" rel="nofollow noreferrer">website</a>を持って
- 4. <a href="http://visjs.org/" rel="nofollow noreferrer">vis.js</a>の項目を編集可能にするにはvis.js
- 5. 私はXfilesharing(perlの)ここではスクリプトそれの公式サイト(<a href="https://sibsoft.net/xfilesharing.html" rel="nofollow noreferrer">https://sibsoft.net/xfilesharing.html</a>)を持っている要求
- 6. Tabキーは、私が<a href="http://%20http://tulipindia.biz/associate_form.php" rel="nofollow">this form</a>を持って
- 7. は私が<a href="https://cloud.google.com/pubsub/docs" rel="nofollow noreferrer">Pub/Sub</a>トピック+サブスクリプションを持っているし、消費し、<a href="https://cloud.google.com/dataflow/docs" rel="nofollow noreferrer">Dataflow</a>にサブスクリプションからの無制限のデータを集計するデフォルトのトリガー
- 8. ハイライトは、私は次のコードを持っている<a href="https://github.com/mojombo/jekyll" rel="nofollow">jekyll</a></p> <p>で<a href="http://pygments.org/" rel="nofollow">pygments</a>を使用したい
- 9. 私は<a href="http://doc.qt.io/archives/qt-4.7/qtcpserver.html" rel="nofollow">QTcpServer</a>のサブクラスを持ってQTcpServer
- 10. .htaccessファイルは、私はDebianの8の上だと私は<a href="http://my-domain.unice.fr/social" rel="nofollow">http://my-domain.unice.fr/social</a>でウェブサイトを持っていると私は私が持っている私の.htaccessで<a href="http://my-domain.unice./" rel="nofollow">http://my-domain.unice./</a></p> <p>でこれをリダイレクトしたい
- 11. JS:<a href="https://jsfiddle.net/qftcjcbp/3/" rel="nofollow"><strong>JS Fiddle</strong></a>:リンク私はカルーセルを持っているカルーセル
- 12. Firebase JS入手トークンは、()私は<a href="https://firebase.google.com/docs/cloud-messaging/js/client" rel="nofollow">Google's Documentation</a>に基づいて、次のコード、持っているトークン
- 13. jQueryの文句を言わない私が<a href="http://jsfiddle.net/buyC9/148/" rel="nofollow">here(JSFiddle)</a>ライブのコードを持っているキー操作
- 14. 私は<a href="https://core.telegram.org/bots/" rel="nofollow noreferrer">telegram bot</a>を作るために、次のコードを持っているPHP
- 15. :私は<a href="http://[email protected]/LabelMeAnnotationTool/tool.html" rel="nofollow noreferrer">http://[email protected]/LabelMeAnnotationTool/tool.html</a>にリンクするとLabelMeAnnotationTool
- 16. は、私は、外部URL(<a href="http://www.google.com" rel="nofollow">http://www.google.com</a>例)に名前test1にinstaceているムービークリップをリンクしたい3.0
- 17. FacebookのJS SDKは、私が<a href="http://apps.facebook.com/insideny/" rel="nofollow">http://apps.facebook.com/insideny/</a></p> <p>でFBのキャンバスアプリを持っているFB.Login
- 18. LinuxのAPPENDパスは、私が<a href="https://github.com/pyenv/pyenv" rel="nofollow noreferrer">pyenv</a>をインストールしている
- 19. のGimp:Pythonスクリプトは、私が<a href="http://www.ibm.com/developerworks/library/os-autogimp/" rel="noreferrer">this</a>チュートリアルに従っ
- 20. 私は<strong><a href="https://github.com/carhartl/jquery-cookie" rel="nofollow">jquery cookie</a></strong>プラグインを使用して、ここに私のコードです名前
- 21. は、私がこの<a href="http://pastebin.com/B8ERBD4L" rel="nofollow">SQL</a></p> <p>を持っているか、SQLサーバー
- 22. HTML5のビデオは、私は同じコードで<a href="http://sprnv.sg" rel="nofollow noreferrer">http://sprnv.sg</a>と<a href="http://creazidigital.com/supernova" rel="nofollow noreferrer">http://creazidigital.com/supernova</a>にウェブサイトのリンク先ページにHTML5のvideoタグを含めることを試みた
- 23. は、私は、「変数」という名前の次<a href="http://www.lihaoyi.com/fastparse/" rel="nofollow noreferrer">fastparse</a>パーサを持って
- 24. DVWAは、私が<a href="http://www.dvwa.co.uk/" rel="nofollow noreferrer">DVWA</a>を設定している
- 25. は私が<a href="https://i.stack.imgur.com/CoiNq.png" rel="nofollow noreferrer">login</a></p> <p>を持っているかアンドロイド
- 26. は私が<a href="https://www.mercurial-scm.org/quickstart" rel="nofollow noreferrer">this article</a>に従っ
- 27. は、私はSASS <a href="http://sass-lang.com/guide" rel="nofollow">inheritance</a>を使用することによって自分自身のサブ要素に<a href="http://getbootstrap.com/" rel="nofollow">Bootstrap</a> CSSを追加するノード
- 28. A HREFリンクは常に
- 29. 私はHREFを持っているスタイル
- 30. のビルド要件に私がソフトウェア製品(<a href="https://NJOY.github.io" rel="nofollow noreferrer">NJOY</a>)のデベロッパービルド環境
+1は、私が「stringToSend」変数は –
@Richard Hけれども冗長であると思います:)それに私を打ちます。それが静的な文字列であれば、それもインラインに置くことができます。 – pimvdb
多くの人々は、window.location.hrefを提案しています。私はこれを避けるでしょう。この使用のためにhrefが作成され、なぜhrefを使用するのですか? ShankarSangoliはあなたに最も良い方法です... – markzzz