克隆表行不起作用

时间:2013-05-01 13:08:43

标签: javascript jquery

我有一个奇怪的问题。我正在为wordpress创建一个元数据盒,并遇到了<tr>无法克隆.click的问题。我正在使用while php循环,可以获得div,p,a等标签来克隆,但不能幸运。这是一个代码。

<?php while($mb->have_fields_and_multi('ingredients')) : ?>
     <?php $mb->the_group_open(); ?>
               <tr>
                 <td>Blah</td>
               </tr>
     <?php $mb->the_group_close(); ?>
<?php endwhile; ?> 

<a href="#" class="docopy">add row</a>

这是javascript

$('[class*=docopy-]').click(function(e)
        {
            e.preventDefault();

            var p = $(this).parents('.postbox'); /*wp*/

            var the_name = $(this).attr('class').match(/docopy-([a-zA-Z0-9_-]*)/i)[1];

            var the_group = $('.wpa_group-'+ the_name +'.tocopy', p).first();

            var the_clone = the_group.clone().removeClass('tocopy last');

            var the_props = ['name', 'id', 'for', 'class',];

            the_group.find('*').each(function(i, elem)
            {
                for (var j = 0; j < the_props.length; j++)
                {
                    var the_prop = $(elem).attr(the_props[j]);

                    if (the_prop)
                    {
                        var the_match = the_prop.match(/\[(\d+)\]/i);

                        if (the_match)
                        {
                            the_prop = the_prop.replace(the_match[0],'['+ (+the_match[1]+1) +']');

                            $(elem).attr(the_props[j], the_prop);
                        }

                        the_match = null;

                        // todo: this may prove to be too broad of a search
                        the_match = the_prop.match(/n(\d+)/i);

                        if (the_match)
                        {
                            the_prop = the_prop.replace(the_match[0], 'n' + (+the_match[1]+1));

                            $(elem).attr(the_props[j], the_prop);
                        }
                    }
                }
            });

            if ($(this).hasClass('ontop'))
            {
                $('.wpa_group-'+ the_name, p).first().before(the_clone);
            }
            else
            {
                the_group.before(the_clone);
            }

            checkLoopLimit(the_name);

            $.wpalchemy.trigger('wpa_copy', [the_clone]);
        });

    });

我为javascript的数量道歉,我无法像jsfiddle那样复制问题。

0 个答案:

没有答案
相关问题