JQuery clone()和append() [英] JQuery clone() and append()

查看:116
本文介绍了JQuery clone()和append()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表:

<table id='table_actions'">
    <tbody class='actions_body'>
        <tr>
            <td colspan=2 class="taskname"><strong>1. </strong><span name='taskname'>name</span></td>
        </tr>
        <tr>
            <td>Действие: </td>
            <td>
                <select name='action_action'>
                    <option value="1">Consult</option>
                    <option value="2">Activate</option>
                    <option value="3">Connect</option>
                </select>
            </td>
        </tr>
        <tr>
            <td><button id='addaction' class="btn">Добавить действие</button></td>
            <td></td>
        </tr>
    </tbody>
</table>

和JQuery代码:

$('#addaction').click(function() {
    $('.actions_body tr:not(:last)').clone()
      .insertBefore($('#table_actions tr:last'));
});

$('select[name=action_action]').change(function() {
    alert();
});

我的问题:通过更改表中克隆部分中的选择,没有任何警报。

My problem: by changing selection in the cloned part of the table, there is no alert.

推荐答案

使用$ $ $ C $ withDataAndEvents boolean参数: / p>

use the withDataAndEvents boolean parameter:

$('.actions_body tr:not(:last)').clone(true)




.clone([withDataAndEvents])

withDataAndEventsA布尔值,表示事件处理程序是否应与元素一起复制。

withDataAndEventsA Boolean indicating whether event handlers should be copied along with the elements.

docs

这篇关于JQuery clone()和append()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆