简体   繁体   中英

Jquery Duplication in mobile vs. of table

I am making a mobile version of my tables, I'm using the following script to help do so:

<script>
$(document).ajaxSuccess(function () {
    $('table#CustomerMainTable td').each(function () {
        var idx = $(this).index();
        $(this).prepend($('table#CustomerMainTable tr th').eq(idx).text());
        $('table#CustomerMainTable th').hide();
    });
});
</script>

This works fine in my fiddle : http://jsfiddle.net/2EJy3/1/

But in my app, it creates duplicates eg. The td would have the th printed twice, instead of once. Does anyone know what would be causing this?

Since it works in your fiddle, that implies a couple of things: 1) Your document structure is different in your app, or 2) your ajaxSuccess handler is being called twice. Turn on your debugger, or add some logging in your script before your each() call and see if the handler is being invoked twice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM