Jquery change()函数不起作用

时间:2010-10-13 01:45:03

标签: jquery-plugins jquery jquery-selectors

我有两个表,我希望在一个表上有更改事件。 那是当我点击第一个表时,我想对第二个表进行一些更改。但不知何故,下面的改变功能不起作用。有什么建议吗?

$("#history_table table:eq(0)").click(function(){
                    $("#history_table table:eq(1) thead tr th:nth-child(1)").html("New");
                }); 

$("#history_table table:eq(1) thead tr th:nth-child(1)").change(function() {
                      alert('Handler for .change() called.');
                });

这里history_table是一个div标签id,它有两个表。 click()函数正在运行,但我也希望看到警告消息,但这没有显示。

1 个答案:

答案 0 :(得分:4)

.change()事件/处理程序不适用于(或默认情况下为),它适用于输入样式元素更改数据,例如<input><select>。相反,您需要一个自定义事件(或手动触发change ...),例如:

$("#history_table table:eq(0)").click(function(){
  $("#history_table table:eq(1) thead tr th:nth-child(1)").html("New")
     .trigger('myEvent');
}); 

$("#history_table table:eq(1) thead tr th:nth-child(1)").bind('myEvent', function() {
  alert('Handler for .change() called.');
});