Jquery:Selector找不到类?

bri*_*ill 3 javascript jquery jquery-selectors

我正在尝试推进Jquery-autcomplete功能.我希望Jquery-autocomplete在表中创建新行.这到目前为止工作.但我希望Jquery添加一个删除按钮.因此,用户可以删除其中一个添加的项目.

    $(document).ready(
function() {


//create an new <tr> <td> in #log   
    function log( message ) {
        $("<tr> <td>"  + message + "<input class='Entf' type='button' value ='Entfernen' />" + "</td></tr>").appendTo("#log");
        $( "#log" ).attr( "scrollTop", 0 );}


// get the values from a json-source
        $( "#REMOTE" ).autocomplete({
            source: "json.php",
            minLength: 0,
            select: function( event, ui ) {
                log( ui.item ?
                    ui.item.value + " aka " + ui.item.id :
                    "Nothing selected, input was " + this.value );}
});


// this is just a test if jquery recognizes the click       
         $('.Entf').click(function(event){
     alert("Thanks for visiting!");
   });
    });
Run Code Online (Sandbox Code Playgroud)

但是jQuery不会识别它创建的元素的点击.为了检查fpr erros,我在html中放了一行.这个按钮有效.但是当我通过Jquery添加一行时,添加的按钮不起作用.这是一个来自firebug的例子:

<table id="log" border="0" width="400">
<tbody>
<tr>
<td>
test
<input class="Entf" type="button" value="Entfernen">         //this one workes fine. it comes from the original html
</td>
</tr>
<tr>
<td>
daniel aka 121
<input class="Entf" type="button" value="Entfernen">     //this one doesn't work. it's the one that was added by Jquery
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

谢谢!好好用我的英文:)

Nea*_*eal 5

使用jQuery live():

$('.Entf').live('click',function(event){
     alert("Thanks for visiting!");
   });
Run Code Online (Sandbox Code Playgroud)

使用live可以使jQuery在由javascript动态创建的选择器上使用回调