Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js new url

作者:碎花洋裙的优雅   发布日期:2025-10-08   浏览:68

// 创建一个新的 URL 对象
const url = new URL('https://example.com:8080/path/to/resource?query=string#fragment');

// 解释说明:
// 1. 'https://example.com:8080/path/to/resource?query=string#fragment' 是传入的 URL 字符串。
// 2. new URL() 构造函数用于创建一个表示绝对 URL 的 URL 对象。
// 3. 可以通过 URL 对象的属性访问 URL 的各个部分,例如:

console.log(url.protocol);   // 输出: "https:"
console.log(url.host);       // 输出: "example.com:8080"
console.log(url.pathname);   // 输出: "/path/to/resource"
console.log(url.search);     // 输出: "?query=string"
console.log(url.hash);       // 输出: "#fragment"

上一篇:js 获取url地址

下一篇:js substring()用法

大家都在看

js 数组对象排序

js 数组删掉第一个值

js fill

js 数组连接

js json数组

js 数组复制

js 复制数组

js 数组拷贝

js 对象数组合并

js 对象转数组

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站