且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将Query-String参数添加到静态链接中

更新时间:2023-12-03 09:06:52

有很多方法可以做到这一点。下面我列出了两个非常简单的方法。在这里,我假设你已经参考了你的 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);