-1

这有什么问题?我只想输出www.google.com

 <script type="text/javascript"> window.onload=function() {  
  var links = document.getElementsByTagName("a");   
   for (var i=0, n=links.length;i<n;i++) {      
     var string = links[i];     
     var str = string;  
     document.write(string);    
     var spl = string.split("/");   
     document.write(spl[2]);       
  } 

  } 

  </script> 

  <a href="http://www.google.com">google</a></br> 
4

5 回答 5

1

您需要获取 href 值:

window.onload=function() {  
  var links = document.getElementsByTagName("a");   
  for (var i=0, n=links.length;i<n;i++) {      
  var string = links[i].href; //href value
  var str = string;    
  var spl = string.split("/");   
  document.write(spl[2]);       
 } 
于 2013-06-05T13:39:09.663 回答
0
var url = "http://www.google.com";
alert(url.split("://")[1]);

工作示例:http: //jsfiddle.net/mE3y6/

于 2013-06-05T13:36:39.303 回答
0

var url = 链接[i].href.replace(/^https?:\/\//, '')

于 2013-06-05T13:32:11.843 回答
0

用 jquery 这样做:

var ancors = $(document).find('a');
    ancors.each(function(){ 
        var url_parts = $(this).attr('href').split('//');
        alert(url_parts[1]);
});
于 2013-05-31T14:34:56.737 回答
0
<script type="text/javascript"> 

  window.onload=function() {  
  var links = document.getElementsByTagName("a");            
var spl = links.split("://");
document.write(spl[1]);    
 } 



 </script> 

 <a href="http://www.google.com">google</a></br>
于 2013-06-05T13:35:38.253 回答