2012-06-26 18 views
0

在包含多個網址的頁面上,我希望能夠刪除網格中的空白並用連字符替換它。 我可以在那裏我有一個單一的網址,但我遇到了多個URL的情況。 我認爲劇本必須使用each(function()) 基於我用於單版本的版本我試過如下:如何刪除多個網址上的空白

$(document).ready.(function() { 
     $('a.testlink').each(function() { 
      var Text = $(this); 
      Text = Text.toLowerCase(); 
      Text = Text.replace(/[\s]+/g,'-'); 
      $(this).attr("href", Text);  
    }); 
     }); 

但劇本完全失敗有對URL沒有影響 - 它既不使下面的情況下,也沒有取代空白。

如何讓腳本遍歷每個href並替換在slug中找到的空間。

回答

2

我相信var Text = $(this);應該是var Text = $(this).attr("href");