📜  Node.js URL.search API

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

Node.js URL.search API

URL.searchNode.JSURL 类的内置应用程序编程接口 (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);

输出: