Javascript 如果单击,则仅重新加载TR

Javascript 如果单击,则仅重新加载TR,javascript,php,jquery,ajax,twitter-bootstrap,Javascript,Php,Jquery,Ajax,Twitter Bootstrap,我在HTML表的和中列出了SQL中的项。该表位于一个div内,该div每30秒用jQuery AJAX刷新一次,这就是div具有唯一id的原因。以下是HTML: 功能自动加载 { $.ajax{ url:/folder/content.php, cache:false, 成功:functiondata{ $live.htmldata; } }; } $document.readyfunction{ auto_load;//在DOM就绪时调用auto_load函数 }; setInterval

我在HTML表的和中列出了SQL中的项。该表位于一个div内,该div每30秒用jQuery AJAX刷新一次,这就是div具有唯一id的原因。以下是HTML:

功能自动加载 { $.ajax{ url:/folder/content.php, cache:false, 成功:functiondata{ $live.htmldata; } }; } $document.readyfunction{ auto_load;//在DOM就绪时调用auto_load函数 }; setIntervalauto_负载,30000; 身份证件 名称
不确定你到底想要什么,但如果我知道你想加载行?因此,您需要侦听对行的单击,读取单元格,进行ajax调用,并替换内容

$("#live").on("click", "tbody tr", function() {  //listen for click on a table row
    var tr = $(this),  //the row
        tds = tr.find("td"),  //the cells of the row
        id = tds[0].text(),  //the first column text
        output = tds[1]; //where to output

    $.ajax({
        method: "POST",
        url: "some.php",  //where to post the data
        data: { id: id }  //value to pass to the server
    })
    .done(function( result ) {
        output.html(result);   //output the returned value
    })
    .fail(function() {
        alert( "error" );
    });
});
如果这不正确,并且希望加载整个表,那么只需查找树以获取div

$(document).on("click", "tr", function() { 
    var div = $(this).closest("div");
    console.log(div.attr("id"));
    div.load("foo.php?id=" + div.attr("id")); 
});
$'myTable'。单击,'.someClass',函数{ var trID=$this.attr'id'; $this.find'td'.appendnew Date;//将其替换为AJAX调用 }; 点击我1 点击我2
因此,检测对TD的点击,获取id,进行ajax调用,替换HTML。您对哪一部分有意见?谢谢您的快速回复。我编辑了一点文本,指的是TR-s,而不是现在的td-s。问题是,我对Javascript知之甚少,因此甚至不知道要寻找什么。也许有人能给我举一些简单的例子。你可以从阅读开始