开发者

Getting all links on the page into form fields w\jQuery

I am working on an app that helps with Information Architecture. I am at the point where I need to get the links on a page 开发者_运维技巧entered into form fields. Is there a way to point the page URL and have all links intered into the text fields?

I think jQuery should have enough power to do this type of work... Perhaps I need to look for $('a') and end everything withing tags? I need the link text only, not the URL itself. Not really sure how, but I feel it should be possible.


The below script, on DOM load, will create one text input control containing the link text of each anchor tag on the page (just copy paste into your page):

<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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜