📜  节点 | URL.search API

📅  最后修改于: 2022-05-13 01:56:57.318000             🧑  作者: Mango

节点 | URL.search API

URL.searchNode.js的内URL类的一个内置的应用程序编程接口(API)。
URL.search API 用于获取和设置 URL 的查询部分。

Syntax: url.search
url : It is an object created by URL constructor.

示例1:(获取URL的查询字符串)

javascript
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org/?articles=nodejs");
 
//Getting query string of above created URL_1 object
console.log(URL_1.search);


javascript
//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org");
 
//Setting query string for URL_1
URL_1.search = "articles=web_technologies";
 
console.log(URL_1.href);
 
//Getting query string after setting
console.log(URL_1.search);


输出:



示例2:(设置URL的查询字符串)

javascript

//Creating an URL_1 object with URL constructor.
const URL_1 = new URL("https://www.geeksforgeeks.org");
 
//Setting query string for URL_1
URL_1.search = "articles=web_technologies";
 
console.log(URL_1.href);
 
//Getting query string after setting
console.log(URL_1.search);

输出: