1,nodejs启动
2,url
[url.parse](url,if,if) url解析
参数依次为:需要解析的url
> url.parse('http://www.jianshu.com/writer#/notebooks/12532849/notes/18716228')
Url {
protocol: 'http:', //url的协议,没有返回null
slashes: true,//是否有协议的双斜线'('//'),没有返回null
auth: null,
host: 'www.jianshu.com', //域名
port: null, //端口
hostname: 'www.jianshu.com',
hash: '#/notebooks/12532849/notes/18716228',//hash值,url的锚点(#注1)
search: null, //查询参数
query: null, //路由查询参数,search是字符串,query同时可以通过配置转成json
pathname: '/writer',//路径名
path: '/writer',//路径
href: 'http://www.jianshu.com/writer#/notebooks/12532849/notes/18716228' }
>
url.parse('www.imooc.com:8080/video/6711?a=1&b=2',true,true)
Url {
protocol: 'www.imooc.com:',
slashes: null,
auth: null,
host: '8080',
port: null,
hostname: '8080',
hash: null,
search: '?a=1&b=2',
query: { a: '1', b: '2' },
pathname: '/video/6711',
path: '/video/6711?a=1&b=2',
href: 'www.imooc.com:8080/video/6711?a=1&b=2' }
>
[url.format]将url对象转为地址
> url.format({
... protocol: 'www.imooc.com:',
... slashes: null,
... auth: null,
... host: '8080',
... port: null,
... hostname: '8080',
... hash: null,
... search: '?a=1&b=2',
... query: { a: '1', b: '2' },
... pathname: '/video/6711',
... path: '/video/6711?a=1&b=2',
... href: 'www.imooc.com:8080/video/6711?a=1&b=2' })
'www.imooc.com:8080/video/6711?a=1&b=2'
>
3,querystring
[querystring.stringify({})] 对象转参数字符串
querystring.stringify({name:'zn',age:[1,2,3],weight:''})
'name=zn&age=1&age=2&age=3&weight='
[querystring.stringify({},'')] 对象转参数字符串,第二个参数为连接符,默认为&
> querystring.stringify({name:'zn',age:[1,2,3],weight:''},'.')
'name=zn.age=1.age=2.age=3.weight='
>
[querystring.stringify({},'')] 对象转参数字符串,第三个参数为对象属性连接符,默认为=
> querystring.stringify({name:'zn',age:[1,2,3],weight:''},',',':')
'name:zn,age:1,age:2,age:3,weight:'
>
[querystring.parse()]参数字符串转jsonobject
> querystring.parse('name=zn,a,b&age=1&weight')
{ name: 'zn,a,b', age: '1', weight: '' }
> querystring.parse('name=zn,a,b&age=1&weight=')
{ name: 'zn,a,b', age: '1', weight: '' }
>
[querystring.parse()]参数字符串转jsonobject第二个参数是分隔符,默认为&
> querystring.parse('name=zn,a,b@age=1&weight','@')
{ name: 'zn,a,b', age: '1&weight' }
>
[querystring.parse()]参数字符串转jsonobject第三个参数为对象属性连接符,默认为=
> querystring.parse('name!zn,a,b@age!1@weight','@','!')
{ name: 'zn,a,b', age: '1', weight: '' }
注1 : 锚点
锚点的定位是通过浏览器URL地址的hash触发的。
页面之所以能定位到锚点所在位置,都是因为URL地址中的锚链的作用,而不是点击行为。最好的证据就是,
当重新载入带有锚链的页面时,锚点依然会被定位。
锚点生效条件:
❶. 元素可滚动;
❷. 锚点元素在内部;
锚点简图
网友评论