Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 分区刷新后未添加jQuery类_Javascript_Jquery - Fatal编程技术网

Javascript 分区刷新后未添加jQuery类

Javascript 分区刷新后未添加jQuery类,javascript,jquery,Javascript,Jquery,我有一个jquery代码,当点击按钮刷新时,表数据表被刷新。 但是当它被刷新时,类negative不会添加到td 下面是代码 $("#button-refresh").click(function(){ $("#table-data").load("index.php #table-data"); $("td[name=td-total").each(function() { var text = $(this).text(); var num = p

我有一个jquery代码,当点击
按钮刷新
时,
表数据
表被刷新。 但是当它被刷新时,类
negative
不会添加到
td

下面是代码

$("#button-refresh").click(function(){
    $("#table-data").load("index.php #table-data");
    $("td[name=td-total").each(function() {
      var text = $(this).text();
        var num = parseFloat(text);
        if (num < 0) {
          $(this).addClass("negative");
        }
    });
});
$(“#按钮刷新”)。单击(函数(){
$(“#表数据”).load(“index.php#表数据”);
$(“td[name=td total”)。每个(函数(){
var text=$(this.text();
var num=parseFloat(文本);
if(num<0){
$(此).addClass(“负”);
}
});
});
使用的回调方法

$(“#按钮刷新”)。单击(函数(){
$(“#表数据”).load(“index.php#表数据”,函数(){
$(“td[name=td total”)。每个(函数(){
var text=$(this.text();
var num=parseFloat(文本);
if(num<0){
$(此).addClass(“负”);
}
});
});
});

AJAX调用是异步的,因此
.load()
方法提供了第二个参数,即成功回调:

.load(“url”,函数(响应、状态、xhr){

在回调中放置AJAX响应后要运行的代码

$(“#按钮刷新”)。单击(函数(){
$(“#表数据”).load(“index.php#表数据”,函数(r,s,x){
$(“td[name=td total”)。每个(函数(){
var text=$(this.text();
var num=parseFloat(文本);
if(num<0){
$(此).addClass(“负”);
}
});
});
});

是因为我还是因为我最近看到了很多仇恨?
$("#button-refresh").click(function(){
  $("#table-data").load("index.php #table-data", function() {
    $("td[name=td-total").each(function() {
      var text = $(this).text();
      var num = parseFloat(text);
      if (num < 0) {
        $(this).addClass("negative");
      }
    });
  });
});