在发送请求之前编辑href链接 [英] Edit the href link before send the request

查看:83
本文介绍了在发送请求之前编辑href链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有代码:

 < a class =myLinkhref ='http://www.website.it/'>链接< / a> 

< script type =text / javascript>
var stringToSend =;
$('。myLink')。click(function(){
stringToSend =?param = 1;
});
< / script>

,如您所见,我想添加 stringToSend 到href(所以请求将在 http://www.website。

解决方案方案

只需用新的 href 修改 href ,就完成了。


$ b $ pre $ $('。myLink')。click(function(){
$(this).attr(href,this .href +?param = 1);
});


I have this code :

<a class="myLink" href='http://www.website.it/'>Link</a>

<script type="text/javascript">
    var stringToSend = "";
    $('.myLink').click(function() {
        stringToSend="?param=1";
    }); 
</script>

and, as you can see, I'd like to add stringToSend to the href (so the request will be at http://www.website.it/?param=1).

How can I do it?

解决方案

Just modify the href with new href and you are done.

$('.myLink').click(function() {
    $(this).attr("href", this.href + "?param=1");
});

这篇关于在发送请求之前编辑href链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆