javascript中new url()属性,轻松解析url地址(示例代码)

            // http://localhost:2021/mt-mobi/#/?hospitalId=1&nonceStr=123ASD&outPatId=&hosPatId=&cardNo=8946&signature=02B6DE19271ED3A74F92506E0171A04357832F1D
            const urlParams = new URL("https://www.baidu.com/?q=URLUtils.searchParams&topic=api");
            urlParams.searchParams.has("topic") === true; // true
            console.log(urlParams.searchParams.has("topic") === true)
            urlParams.searchParams.get("topic") === "api"; // true
            urlParams.searchParams.getAll("topic"); // ["api"]
            urlParams.searchParams.get("foo") === ""; // true
            urlParams.searchParams.append("topic", "webdev");//给地址添加参数
            console.log(urlParams)
            console.log(urlParams.toString())
            urlParams.searchParams.toString(); // "q=URLUtils.searchParams&topic=api&topic=webdev"
            urlParams.searchParams.set("topic", "More webdev");
            urlParams.searchParams.toString(); // "q=URLUtils.searchParams&topic=More+webdev",获取地址
            urlParams.searchParams.delete("topic");
            urlParams.searchParams.toString(); // "q=URLUtils.searchParams"

你可能感兴趣的:(javascript中new url()属性,轻松解析url地址(示例代码))