0

Ajax の完了後に呼び出す次の関数があります。

function name(results)
{       
    var str='';

    str+='<div id="newDiv"></div>';
    str+='<input type="text" value="'+results.name+'" id="newTextbox"></input>'; 

   $('#otherDiv').html(str);  
}

それから私は使用newDivnewTextboxました

$('#newDiv').html('Example Text');

それは私にとってはうまくいきます。しかし、私が使用するとき

$('#newTextbox').click(function(){
     alert('CLICK WITHOUT LIVE');
});

動作していません。次に、次のように変更しました。

$('#newTextbox').live("click",function(){
     alert('CLICK WITH LIVE');
});

それは私のために働いています。

私の質問は、両方 ( newDivnewTextbox) が動的に作成されることです。

$('#newDiv').html('Example Text');live を使わずに動作しているのに、クリックイベントが動作しないのはなぜnewTextboxですか?

4

2 に答える 2