var URL = require('url'); 
var p = URL.parse(testUrl); 
console.log("------------------href : " + p.href); //取到的值是:http://www.baidu.com:8080/index.php?content=abc 
console.log("------------------requestHead: " + p.protocol); //取到的值是:http: 
console.log("------------------hostname: " + p.hostname);//取到的值是:www.baidu.com 
console.log("------------------host:" + p.host);//取到的值是:www.baidu.com:8080 
console.log("------------------port: " + p.port);//取到的值是:8080 
console.log("------------------path: " + p.path);//取到的值是:/index.php?content=abc 
console.log("------------------hash: " + p.hash);//取到的值是:null 
console.log("------------------query: " + p.query);//取到的值是:content=abc,在此值得注意的是当语句是 var p = URL.parse(testUrl, true) 时,p.query则返回的是如:{content:'abc'}这样的对象,直接打印p.query则返回 [object Object],这时我们可以这样写: var pp = p.query; console.log("------------------content: " + pp.content);//取到的值是:abc 
console.log("------------------pathname: " + p.pathname);//取到的值是:/index.php

相关文章:

  • 2021-06-24
  • 2022-02-15
  • 2021-08-03
  • 2021-11-24
  • 2022-02-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-26
  • 2022-02-25
  • 2021-09-25
  • 2021-06-23
  • 2021-10-05
  • 2021-09-19
  • 2021-11-20
相关资源
相似解决方案