为URL或 href 插入 或 替换原有的标签。
由于该方法属于url模块,使用前需要引入url模块(var url= require(“url”) )
var url = require('url');
var a = url.resolve('/one/two/three', 'four') ,
b = url.resolve('http://example.com/', '/one'),
c = url.resolve('http://example.com/one', '/two');
console.log(a +","+ b +","+ c);
输出结果:
/one/two/four
http://example.com/one
http://example.com/two
原型
Url.prototype.resolve = function(relative) {
return this.resolveObject(urlParse(relative, false, true)).format();
};