-1

如果它的类等于其他 div 的(编号 2)类值,我想更改 div 容器(编号 1)的值。

首先,我得到 2 号 div 的值:

  var classId = $(this).attr('class').split(' ')[1];

它有两个类,第二个是我正在使用的。

接下来,我尝试比较值并更改 div 编号 1 内的数据:

$.ajax(test.base_url + "name/name/" + ID, {
cache: false,
success: function(data, textStatus, jqXHR) {
    if ($("#redChar").attr("class") == classId) {
        $("#redChar").find('.'+classId).html(data);
    }
    else {
        $("#redChar").html();
    }

},
dataType:"html"
});

我做错了什么?

4

1 回答 1

1

你应该使用$("#redChar").hasClass(classId)

此外,如果您想更改 的内容$("#redChar"),您可以将其取出find()并将更改直接应用于它:$("#redChar").html(data);

于 2012-12-06T07:30:47.537 回答