【问题标题】:Jquery change() function not workingJquery change()函数不起作用
【发布时间】:2011-04-24 15:09:50
【问题描述】:

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

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

【问题讨论】:

    标签: jquery-plugins jquery jquery-selectors


    【解决方案1】:

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

    【讨论】:

    • 谢谢尼克,它工作正常。但是如果我想让我的第二个表始终监听一个事件,而不是从另一个函数调用触发器,我想在有人更改第二个表值时自动显示警报消息。有什么办法吗?
    • @goutham - 不是内置的跨浏览器,不...监控起来会非常昂贵:)
    猜你喜欢
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    • 2012-06-28
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多