2010-10-13 68 views
1

我有两个表,我想在一个表上有更改事件。 这就是当我点击第一张桌子时,我想对第二张桌子进行一些更改。但不知何故下面的改变功能不起作用。有什么建议么?jquery更改()函数不起作用

$("#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()函数正在工作,但我期望看到警报消息,但这并未显示。

回答

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.'); 
}); 
+0

感谢尼克,它工作正常。但是如果我想让我的第二个表总是监听一个事件,而不是从另一个函数调用触发器,那么当有人更改第二个表值时,我会自动显示警报消息。有什么办法吗? – jgg 2010-10-13 17:47:25

+0

@goutham - 不是一个内置的跨浏览器一个nope ...这将是非常昂贵的监测:) – 2010-10-13 22:11:45