首页 > 解决方案 > 为什么我不能用 jQuery 删除 DOM 元素?

问题描述

这是我的一段代码,它应该只是从 HTML DOM 中删除一个元素,但由于某种原因它不会......

...
clearError(fields['server_error'][fieldUniqueId], 'server_error');
...

function clearError($field, type){
    $("#" + getErrorLabelId($field, type)).remove();
}

function getErrorLabelId($field, type){
    return ValidatorInstance.ErrorLabelIdPrefix + "-" + $field.data(ValidatorInstance.uniqueIdKey) + "-" + type;
}

所有函数都工作并返回它们期望的值。例如,如果我将线从更改为$("#" + getErrorLabelId($field, type)).remove();完美$("#" + getErrorLabelId($field, type)).css('background.color', 'blue');设置背景颜色。但它不会删除。这是为什么?

标签: javascriptjquery

解决方案


推荐阅读