Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

jquery - How to get text file using .each method,

I have this html code: I want to $.get a .txt file with the same name as the div id and show in the respective divs But is returning the same file to all the divs, also is loading the last file/div id.

How can I achieve this?

    <div class="addId" id="qwerty" ><div class="parent"></div></div>
    <div class="addId" id="ytrewq" ><div class="parent"></div></div>
    <div class="addId" id="asdfgh" ><div class="parent"></div></div>
    <div class="addId" id="bruno" ><div class="parent"></div></div>

and this script:

function loadTxt(){
    $('.parent').each(function(){
    var txtId = $(this).parent().attr('id');

    $.get( "./"+txtId+'.txt', function( data ) { var resourceContent = data; 
    $('.parent').html(data)}) }) };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...