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

发布于 2024-09-18 19:54:03 字数 207 浏览 4 评论 0原文

我有一个 Html 表,其中包含动态生成的行(从 PHP) 每行都包含带有值的选择框和文本框。 现在我如何知道哪一行已更改(我的意思是选择框和文本框)。 我希望有一个已更改的 (1,3,5,7) 行列表,以便 我可以将它们传递给隐藏并在 php 中检索

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

 });

I have a Html Table which consists of rows that were generated dynamically (from PHP)
and each row conatins the select box and textbox with the values.
Now how do i know which row has been changed (i mean Select box and textbox).
Iam looking to have a list of (1,3,5,7) rows that have been changed so that
i can pass them to the hidden and retrive in php

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

 });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

恋竹姑娘 2024-09-25 19:54:03

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

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

You can monitor object for changes. Give the input's (I'm assuming they are inputs) a class of monitor and run

$(".monitor").bind("keyup", function(event){ /* Code */ });
短暂陪伴 2024-09-25 19:54:03

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

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

That will give you the index of the row, which has been changed

(function() {
  $("table").change(function(e) {
    alert($(e.target).closest("tr").index());
  });
})();​
樱花细雨 2024-09-25 19:54:03

尝试以下代码:

$("#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
        });
    }
}

try this code:

$("#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'); 
});

You will need to give each row a unique id number, and use the following code to handle the submission:

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
        });
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文