方法說明:
為URL或 href 插入 或 替換原有的標簽。(不懂可以看例子)
語法:
代碼如下:
url.resolve(from, to)
由於該方法屬於url模塊,使用前需要引入url模塊(var url= require(“url”) )
接收參數:
from 源地址
to 需要添加或替換的標簽
例子:
代碼如下:
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();
};