在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?
发布评论