我如何知道jquery中表中已更改的值

时间:2010-09-10 19:54:08

标签: javascript jquery jquery-selectors

我有一个Html表,其中包含动态生成的行(来自PHP) 每行包含选择框和文本框的值。 现在我怎么知道哪一行已被更改(我的意思是选择框和文本框)。 我希望有一个(1,3,5,7)行的列表已被更改,以便 我可以将它们传递给php中的隐藏和反向

 ("#tb11").change(function(){
  //Code 

 });

3 个答案:

答案 0 :(得分:2)

您可以监视对象的更改。给输入(我假设它们是输入)一类monitor并运行

$(".monitor").bind("keyup", function(event){ /* Code */ });

答案 1 :(得分:1)

这将为您提供已更改的行的索引

(function() {
  $("table").change(function(e) {
    alert($(e.target).closest("tr").index());
  });
})();​

答案 2 :(得分:-2)

试试这段代码:

$("#tb11 input").change(function(){
      // Gets the parent row of the item that has been changed and adds a class of changed
      $(this).parent().parent().addclass('changed'); 
});

您需要为每一行指定唯一的ID号,并使用以下代码处理提交:

function submitForm() {
    $('.changed').each(function () {
        // Will loop through each row that has been changed and post a value based on the id attribute
        var rowId = $(this).attr('id');
        // post the value of your row id to php
        $.post('myurl.php?rowId='+rowId, function(data) {
            //callback method for succesfull post
        });
    }
}