我有一个像以下网址:
http://www.intereconomia.com/noticias-gaceta/politica/grinan-los-casos-corrupcion-pueden-influir-20120226
Run Code Online (Sandbox Code Playgroud)
我只想在我的链接文字中:
http://www.intereconomia.com
Run Code Online (Sandbox Code Playgroud)
但是href转到:
http://www.intereconomia.com/noticias-gaceta/politica/grinan-los-casos-corrupcion-pueden-influir-20120226
Run Code Online (Sandbox Code Playgroud)
什么正则表达式jquery可以做这个功能?
而不是使用正则表达式,你可以尝试这是干净和简单的.
$('a').each(function(){
$(this).text(this.protocol + "//" + (this.hostname || this.pathname));
});?
Run Code Online (Sandbox Code Playgroud)
注意:如果您只想为锚点设置它,那么相应地更改选择器,但内部逻辑保持不变.
工作演示 - http://jsfiddle.net/ShankarSangoli/8G7JM/3/