0

嘿,所以我有这个代码:

$('#album_cell' + currentCell).toggle(
    function() {
        $('#album_cell'+currentCell).flip({
            direction:  'lr',
            color:      "#FFF",
            content:    '<?php echo form_open('subjects/insert_caption');?>'
                      + '<textarea id="caption_input' + currentCell + '">'
                      + '   <?php echo $this->lang->line('insert_catpion_text'); ?>'
                      + '</textarea>'
                      + '<input type="submit" id="submit_caption' + currentCell + '" value="<?php echo $this->lang->line('save'); ?>" /> '
                      + '<?php echo form_close(); ?>'
                      + ''
        });
    },
    function() {
        $('#album_cell'+currentCell).revertFlip();
    }
);

我正在使用 CodeIgniter 和jQuery Flip 插件,这是不相关的,但向你们中的一些人解释了未知代码。

现在所有数据都是正确的,插件在第一次点击后会创建一些内容,并按预期恢复为原始内容。

现在我的问题是如何在创建的内容上绑定一个事件,以便单击内部文本区域/按钮不会触发该toggle方法?

编辑:

根据要求,这是输出的 HTML:

<form action="http://localhost/ci/index.php/subjects/insert_caption" method="post" accept-charset="utf-8">
    <textarea id="caption_input1">add</textarea>
    <input type="submit" id="submit_caption1" value="save">
</form>

我试过了 :

                    $('#album_cell'+currentCell).on(
'click','#caption_input'+currentCell,function() {
                     alert();
                     e.stopPropagation();
                    });

但这不起作用,它确实触发了事件,但仍然切换。

4

1 回答 1

3

您必须在.on()函数中添加选择器以将事件绑定到动态创建的元素。

尝试类似的东西(哪里body过于宽松,使用您加载数据的容器):

$('body').on('click','#caption_input'+currentCell,function(e) {
    e.stopPropagation();
});
于 2012-10-21T08:35:02.707 回答