在我自己的回答中解决了:
Explanation__:
.removeClass()不接受逗号来列出多个类。
我正在构建一个充满单元格的智能数据网格,它将识别(在模糊上)它们是否被更改,以及值是上升还是下降。
看上去是这样的。当用户悬停一个已更改的框并告诉他们页面第一次加载时值是什么时,就会出现灰色工具提示。

问题:当我降低单元格中的值时,模糊化,然后将其更改回原来的值,该单元格将正确地删除它被更改的所有指示(没有红色/绿色边框,没有箭头,没有工具提示)。
然而,当我在单元格中提高值时,模糊化,然后将其更改为原来的值,这并不是要去掉绿色的边框。我已经检查了我的代码,我不明白它为什么不删除"up“类。
示例:将左上角单元格从12,000更改为11,000。点击关闭单元格。注意红色边框。现在改回12,000。现在应该重新设置为灰色。 现在将值更改为13,000。点击关闭单元格。注意绿色边框。现在改回12,000。当它应该重新设置为灰色时,它仍然是绿色的。
你们能给我第二双眼睛找出我的问题所在吗?或者建议一种压缩我的“细胞重置”的方法?
与(这里有完整的代码):相关的
<tr>
<td><input type="text" value="12000" /></td>
<td><input type="text" value="1000" /></td>
<td><input type="text" value="100000" /></td>
</tr>相关CSS (这里有完整的代码):
.up { border:1px solid #0F0 !important; }
.down { border:1px solid #F00 !important; }
.down-indicator {
// some styles to create a downward triangle
}
.up-indicator {
// some styles to create an upward triangle
}相关(这里有完整的代码): 相关jQuery
$(function() {
var initialValues = [];
$('input').each(function(index) {
initialValues[index] = $(this).val();
$(this).data('id', index);
});
$("input").blur(function() {
var $t = parseInt($(this).val(), 10);
var $s = parseInt(initialValues[$(this).data('id')], 10);
// value has changed
if($t != $s) {
$(this).parent().append("<div class='tooltip'>" + $s + "</div>");
}
// value is the same as initial value
if($t == $s) {
$(this).removeClass("up, down");
$(this).parent().children(".tooltip").remove();
$(this).parent().children(".up-indicator, .down-indicator").remove();
}
// value went up
else if($t > $s) {
$(this).removeClass("up, down");
$(this).parent().children(".up-indicator, .down-indicator").remove();
$(this).addClass("up");
$(this).parent().append("<div class='up-indicator'></div>");
}
// value went down
else if($t < $s) {
$(this).removeClass("up, down");
$(this).parent().children(".up-indicator, .down-indicator").remove();
$(this).addClass("down");
$(this).parent().append("<div class='down-indicator'></div>");
}
});发布于 2013-02-28 19:56:43
我发现了我的问题。.removeClass()似乎不使用逗号来分隔多个类。
旧代码:
$(this).removeClass("up, down");固定代码:
$(this).removeClass("up down");https://stackoverflow.com/questions/15144386
复制相似问题