简体   繁体   English

带有变量选择器的jQuery不起作用

[英]Jquery with variable selector doesn't work

I don't know why the selector jquery doesn't accept a variable. 我不知道为什么选择器jquery不接受变量。

function myfunction()
{
    $.ajax({
           url: "/file.php", dataType: "json", type: "GET",
           success: function(data)
           {
              var data = data.split("-");
              data.forEach(function(entry) 
              {
                 if (entry != "")
                 {
                     $("#check_status_" + entry).html('text');
                 }
              });
           }
    });
}

variable entry is not empty, the problem is when I put it into the selector. 变量条目不是空的,问题是当我将其放入选择器时。 Thanks. 谢谢。

[update] [更新]

{
        var test = "aaa-bbb-ccc";
        var data = test.split("-");

        data.forEach(function(entry) {
            if (entry != ""){
                $("#check_status_" + entry).html('!NEW!');
            }
        });
    }

nothing the same 没什么一样

It seems to work fine if you are achieving something like this 如果您实现了这样的目标 ,则似乎工作正常

data.forEach(function(entry) {
    if (entry) {
        $("#check_status_" + entry).html('text');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM