如何将查询参数添加到URL?

编程入门 行业动态 更新时间:2024-10-14 02:22:37
本文介绍了如何将查询参数添加到URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Tritium(Moovweb SDK)中向URL添加查询参数的最佳实践是什么?在不知道URL是否带有?"的地方寻找有用的东西和其他查询参数.

What's the best practice for adding a query parameter to a URL in Tritium (Moovweb SDK)? Looking for something that works where you don't know if the URL has a "?" and other query parameters already.

推荐答案

以下是Tritium的一小段内容,该内容应该可以帮助您进行Moovweb项目.只需将"query_param = true" 位替换为要添加的查询参数即可.

Here's a short snippet of Tritium that should help you out in your Moovweb project. Just replace the "query_param=true" bit with the query parameter you want to add.

它选择每个a标记的href,然后查找任何现有查询参数(通过在href中查找?").如果存在,则仅追加新的查询参数.如果href上没有现有的查询参数,则使用?.在网址中添加一个.

It selects the href of every a tag, then looks for any existing query parameters (by looking for a "?" in the href). If there are some existing, it just appends the new query parameter. If there are no existing query parameters on the href, it uses the ? to add one to the URL.

$q = "query_param=true" $("//a[@href]") { %s = fetch("./@href") match(%s) { with(/\?/) { attribute("href", %s + "&" + $q) } else() { attribute("href", %s + "?" + $q) } } log(%s) }

(如果需要,您也可以将其转换为函数!)

(You could also turn that into a function if you wanted!)

更多推荐

如何将查询参数添加到URL?

本文发布于:2023-11-26 02:23:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   参数   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!