简体   繁体   English

移动与表中的jQuery复制

[英]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/ 这对我的提琴效果很好: http : //jsfiddle.net/2EJy3/1/

But in my app, it creates duplicates eg. 但是在我的应用程序中,它会创建重复项,例如。 The td would have the th printed twice, instead of once. td将把th打印两次,而不是一次。 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. 由于它在您的小提琴中起作用,因此意味着两件事:1)您的应用程序中的文档结构不同,或2)您的ajaxSuccess处理程序被调用两次。 Turn on your debugger, or add some logging in your script before your each() call and see if the handler is being invoked twice. 打开调试器,或在您的each()调用之前在脚本中添加一些日志记录,然后查看处理程序是否被调用两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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