0
$(".induction-group").bind("DOMSubtreeModified", function(event) {
    $(this).trigger("currentPosition", function( page ) {
        number_of_claims = $(this).find(".claim").length;
            element = $(this).find('.induction-claim-counter').first();
            element.html("Example # " + (page+1) + "/" + number_of_claims);
    });
 });

这在 chrome 中可以正常工作,但完全冻结了 firefox 和 IE

.induction-group 内容

<div class="row claim-depth-<%#= claim.depth - root_claim.depth %>"> 
<div class="claim">
    <div class="claim-id"> <%= claim.id %> </div>   
    <div class="col-xs-1 claim-icon">
        <span class="glyphicon glyphicon-align-justify"></span>
    </div>

    <div class="col-xs-6 claim-text hidden-sm hidden-xs induction-claim-text">
            <div class="induction-background-1"></div>
            <div class="induction-background-2"></div>
            <div class="induction-background-3"></div>
            <div class="prev-claim">
                <span class="glyphicon glyphicon-arrow-left">
            </div>
            <div class="next-claim">
                <span class="glyphicon glyphicon-arrow-right">
            </div>
            <div class="induction-claim-counter"> <-- !!!!!!! -->
            </div>
            <%= claim.text %>   
    </div>
...............

text() 和 val() 函数根本不起作用。有任何想法吗?

4

2 回答 2

1

您可能正在创建一个竞争条件....因为您在监视 DOM 更改的事件处理程序中修改 DOM。如果您解释了使用它的原因,也许您可​​能会得到其他选择

阅读MDN Docs中的 Red disclimer

Be very careful with this event it is easy to cause an infinite loop if you decide to change the DOM inside the event handler.

于 2013-11-02T21:16:57.370 回答
0

也许 jquerys .append () ?我不是 100% 确定

于 2013-11-02T21:14:22.407 回答