将Query-String参数添加到静态链接中 [英] Add Query-String parameter to static link on click

查看:104
本文介绍了将Query-String参数添加到静态链接中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在访问者点击静态锚链接时,我正在寻找一种动态注入查询字符串参数的强大方法。

I'm looking for a robust way of dynamically injecting a query string parameter when a visitor clicks on a static anchor-link.

例如链接: / p>

For example a link:

<a href="http://www.johndoeslink.com">Test</a>

我想将查询字符串传递给下一页,但必须动态分配值。我如何才能实现这一点?

I want to pass a query string to the next page but have to assign the value dynamically. How can I achieve this?

我知道这很简单,我只是想念一些明显的东西! = \

I know this is simple I'm just missing something obvious! =\

提前感谢

John d

推荐答案

有很多方法可以做到这一点。下面我列出了两个非常简单的方法。在这里,我假设你已经参考了你的 a 元素(这里我已经调用了这个元素):

There are many ways you could do this. Below I've listed two very simple methods. Here I'm assuming you already have a reference to your a element (here I've called this element):

element.href += '?query=value';



使用点击事件监听器



Using a click event listener

element.addEventListener('click', function(event) {
    // Stop the link from redirecting
    event.preventDefault();

    // Redirect instead with JavaScript
    window.location.href = element.href + '?query=value';
}, false);

这篇关于将Query-String参数添加到静态链接中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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