簡體   English   中英

遍歷div中的數據

[英]loop through data in div

我想遍歷 div 中的數據。

我想逐行獲取數據。

 <div id="result" runat=server> <div id="gvResult" class="RowGroup"> <div class="Row RowBg" tabindex="99"> <div class="Cell hidden-mobile hidden-tablet"></div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all"> <p>PRM54</p> </div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all wb-keep-all"> <p>YELEK</p> </div> <div class="Cell text-center tooltip-box tooltipstered">10,15 EU</div> </div> <div class="Row RowBgTwo" tabindex="99"> <div class="Cell hidden-mobile hidden-tablet"></div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all"> <p>PRMd54</p> </div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all wb-keep-all"> <p>YELEsK</p> </div> <div class="Cell text-center tooltip-box tooltipstered">10,15 EU</div> </div> </div>

我希望結果是這樣的。

div 中的第一行和 id="1" PRM54-YELEK-10.15EU

div 中的第二行和 id ="2" PRM54d4-YELEK-10.15EU。 . .

我將向您展示一個示例解決方案(它沒有完全實現),您可以嘗試這種方式。

 var idCounter = 1; $('.RowGroup').find('.Row').each(function(){ let text = 'id: ' + idCounter + ' '; $(this).find('div').not(':empty').each(function(){ text += $(this).text().trim() + '-'; }); idCounter++; console.log(text.substring(0,text.length-1)); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="gvResult" class="RowGroup"> <div class="Row RowBg" tabindex="99"> <div class="Cell hidden-mobile hidden-tablet"></div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all"> <p>PRM54</p> </div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all wb-keep-all"> <p>YELEK</p> </div> <div class="Cell text-center tooltip-box tooltipstered">10,15 EU</div> </div> <div class="Row RowBgTwo" tabindex="99"> <div class="Cell hidden-mobile hidden-tablet"></div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all"> <p>PRMd54</p> </div> <div class="Cell ws-normal m-wb-break-all t-wb-break-all wb-keep-all"> <p>YELEsK</p> </div> <div class="Cell text-center tooltip-box tooltipstered">10,15 EU</div> </div> </div>

如果您需要進一步的幫助,請隨時告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM