【问题标题】:jQuery get each attribute and append them to each new divjQuery 获取每个属性并将它们附加到每个新的 div
【发布时间】:2015-12-02 08:19:48
【问题描述】:

我有一个<li> 的列表,类为.boxitem。在每个<li> 里都有一个属性,

exmp---ee_list_itemident="142765"

我想循环每个 boxitem 并在每个 boxItem 中附加一个新的 div

<li class="boxItem auto-height first  grid_4">
    <div class="boxItem-wrap">
        <div class="item-name">
            <a ee_list_itemname="itemname= " ee_list_itemprice="0" ee_list_itemid="50011" ee_list_itemident="14d65" </a>
        </div>
        <div class="MiscFieldsIcons">
            <ul class="MiscIconUl">
            </ul>
        </div>
        <div class="pbcontact">
            <a class="openproductform" href="/product_contact_form.asp?itemident=2345&amp;subject_postfix="/>
        </div>
    </div>
</li>      
<li class="boxItem auto-height first  grid_4">
    <div class="boxItem-wrap">
        <div class="item-name">
            <a ee_list_itemname="itemname= " ee_list_itemprice="0" ee_list_itemid="32344" ee_list_itemident="142765" </a>
        </div>
        <div class="MiscFieldsIcons">
            <ul class="MiscIconUl">
            </ul>
        </div>
        <div class="pbcontact">
            <a class="openproductform" href="/product_contact_form.asp?itemident=2345&amp;subject_postfix="/>
        </div>
    </div>
</li>      

我试图做这样的事情,

$(".boxItem").each(function() {
   var myclass = $(this).find( ".ee_product_click" ).attr('ee_list_itemident');
   var txt = $(this).text();
   $("<span>"+txt+"</span>").appendTo(".boxItem");
 });

它不起作用。

【问题讨论】:

  • 忘了每个盒子Item有不同的itemident属性!
  • HTML 需要重大改进。我什至不知道如何关闭这些divs。
  • 感谢您的回复

标签: javascript jquery html append attr


【解决方案1】:

JSFiddle 包含改进的 HTML 标记和 javascript,可获取每个 .boxItem 的 html 内容

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-25
    • 2016-10-11
    • 2016-03-31
    • 2014-08-04
    • 2018-03-18
    • 2015-07-15
    • 2017-04-03
    • 2020-07-07
    相关资源
    最近更新 更多