- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用程式模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
NodeJS - url.search 屬性
URL 類 的 NodeJS url.search 屬性 獲取並設定 URL 的序列化查詢部分。如果無效的 URL 字元出現在分配給 username 屬性的值中,則會對其進行百分比編碼。百分比編碼的字元選擇可能與 url.parse() 和 url.format() 方法生成的字元略有不同。
Node.js URL 模組提供了多個用於 URL 解析和分析的實用程式,而 search 屬性就是其中之一。
語法
以下是 NodeJS URL 類 的 search 屬性 的語法
URL.search
引數
此屬性不接受任何引數。
返回值
此屬性設定並獲取 URL 的查詢部分。
示例
如果我們將 URL 分配給 NodeJS url.search 屬性,它將從給定的 URL 獲取查詢部分。
在下面的示例中,我們嘗試從輸入 URL 獲取查詢段。
const http = require('url');
const myURL = new URL('https://tutorialspoint.tw/?Node.js-articles');
console.log("The URL: " + myURL.href);
console.log("Query portion of the URL is: " + myURL.search);
輸出
執行上述程式後,search 屬性將從輸入 URL 獲取查詢段。
The URL: https://tutorialspoint.tw/?Node.js-articles Query portion of the URL is: ?Node.js-articles
示例
我們可以將任何有效值設定為提供的 URL 的查詢部分。
在下面的程式中,我們嘗試將值設定為輸入 URL 的查詢部分。
const http = require('url');
const myURL = new URL('https://tutorialspoint.tw/?Node.js-articles');
console.log("The URL: " + myURL.href);
console.log("Query portion of the URL is: " + myURL.search);
myURL.search = "JavaScript-Articles";
console.log("Modifying the query portion to- " + myURL.search);
console.log("After modifying: " + myURL.href);
輸出
正如我們在下面的輸出中看到的,URL 的查詢段已修改。
The URL: https://tutorialspoint.tw/?Node.js-articles Query portion of the URL is: ?Node.js-articles Modifying the query portion to- ?JavaScript-Articles After modifying: https://tutorialspoint.tw/?JavaScript-Articles
示例
如果 URL 的查詢部分包含任何無效的 URL 字元,則這些字元將被百分比編碼。
在下面的示例中,我們分配了一個在使用者名稱部分包含無效字元的 URL。
const http = require('url');
const myURL = new URL('https://tutorialspoint.tw/?你好-Articles');
console.log("The URL: " + myURL.href);
console.log("Value in query portion: " + myURL.search);
輸出
正如我們在輸出中看到的,URL 中的無效字元已進行百分比編碼。
The URL: https://tutorialspoint.tw/?%E4%BD%A0%E5%A5%BD-Articles Value in query portion: ?%E4%BD%A0%E5%A5%BD-Articles
nodejs_url_module.htm
廣告
