0

ページに次のようなjQuery関数を呼び出すボタンがあります。

$('[id^=edit]').one('click',function (){
    id = $(this).attr('id')
    changedId = id.replace('edit', '') // cut off the word 'edit'
    oldValue = $('#' + changedId).text()
    $('#' + changedId).html("<input class='myInput' type='text' value='" + oldValue +"'/>");
    $(this).addClass('success');
    $(this).attr('id', changedId+'Button');
    $(this).text("save it")
});

基本的に、このクリックは段落内に入力要素を作成し、ボタンに別のクラスを追加してから、そのIDを変更します。

新しいIDのボタンがクリックされたときに実行される2番目の関数を作成したいと思います。例えば:

$('[id$=Button]').click(function(){
    alert("it works");

});

このようなことは可能ですか?その新しい関数は私のDjangoアプリへのAJAX呼び出しをトリガーしますが、それは関係ありません。

4

2 に答える 2

0

イベントをまだ存在しない要素に委任する場合は、次を使用ます。

 $(document.body).on('click', '[id$=Button]', function(){
于 2013-03-24T13:51:04.210 に答える
-1

jqueryを使用できます:

$('#' + changedId + 'Button').live('click', function(event) {
   alert('it works');
});
于 2013-03-24T13:58:16.050 に答える