2011-05-23 48 views
0

我在一個應用程序,與信息架構可以幫助工作。我在那裏我需要進入表單域在頁面上的鏈接點。有沒有辦法指向網頁的網址,並有採訪了在文本字段中的所有鏈接?獲取網頁上的所有鏈接到表單域w^ jQuery的

我認爲jQuery的應該有足夠的力量做這種類型的工作。也許我需要尋找$(「a」)和結束一切withing標籤?我只需要鏈接文本,而不是URL本身。不知道如何,但我覺得它應該是可能的。

回答

1

下面的腳本,在DOM負荷時,將創建一個文本輸入控件包含網頁上的每個錨標記的鏈接文字(只是複製粘貼到您的網頁):

<script type='text/javascript'> 
$(function() { 

    var i = 0, 
     inputs = "<input type='text' value='' />"; 

    // loop through each a tag and grab the link text 
    $("a").each(function() { 
     i++; 

     // create a new text field and append to outFields 
     // feel free to change the input tag template above 
     $(inputs) 
     .attr("id", "field" + i) 
     .attr("name", "field" + i) 
     .value($(this).text()) 
     .appendTo("#outFields"); 

    }); 

}); 
</script> 

<div id="outFields"></div> 
+0

他要求每一個環節在自己的文本框中。看到他對觀察者答案的評論。 – doomspork 2011-05-23 16:31:49

+0

更新 - 晚對此有何評論抽獎。 – thastark 2011-05-23 16:34:40

+0

還不遲! :) – santa 2011-05-23 18:53:10

相關問題