2011-07-16 53 views
1

我有一個表HTML輸入按鈕不調用任何jQuery函數

<table style="width: 100%;" class='table_result'> 
    <tr><td>Text</td><td>Text</td><td>Text</td><td>Text</td><td>Text</td><td>text</td></tr> 
</table> 

然後,當按鈕被點擊我把這個

$("table.table_result").append('<tr class="topRow" style="height: 35px;"> 
            <td 'style="text-align: center; cursor: pointer">'+ text 
          +'</td><td style="text-align: center">' 
            +'<input class="control_voteUp" type="button" value="Up">' 
            + text 
            +'<input class="control_voteDown" type="button" value="Dn">' +'</td><td style="text-align: center">'+ text +'</td><td style="text-align: center">'+ text 
          +'</td><td style="text-align: center">'+ text 
          +'</td><td style="text-align: center">'+ text +'</tr>'); 

所以我想,當點擊control_voteUp調用一個函數。

我曾嘗試以正常的方式和其他沒有更迭:

$('input.control_voteUp').click(function() 
{ 
    alert("aa"); 
}); 

$('input.control_voteUp').delegate('input', 'click', function() 
{ 
    alert("aa"); 
}); 

$('input control_voteUp').live('click', function() 
{ 
    alert("aa"); 
}); 

任何解決方案?

回答

2

在您的實時函數調用中,您缺少一個。

變化input control_voteUpinput.control_voteUp

嘗試:

$('input.control_voteUp').live('click', function() 
{ 
    alert("aa"); 
}); 
+0

呀它工作!!我讀了http://stackoverflow.com/questions/3072441/jquery-live-doesnt-work-with-table-rows-on-the-iphone,它沒有點,所以我嘗試了這種方式。我的壞 – gerarddp

1

你必須在delegate調用適用於已存在的元素,在這種情況下表:

$('table.table_result').delegate('input.control_voteUp', 'click', function() { 
    alert("aa"); 
}); 
+0

是的,它也有效 – gerarddp