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とjQueryFlipプラグインを使用しています。これは無関係ですが、未知のコードを説明している人もいます。

これですべてのデータが正しくなり、プラグインは最初のクリック後にコンテンツを作成し、期待どおりに元のデータに戻ります。

今私の質問は、作成されたコンテンツにイベントをバインドして、内側のテキストエリア/ボタンをクリックしても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 に答える