前两个 if 语句有效,但是当它检查选择选项是否具有这两个属性时,它不会显示正确的消息。如何更改它以允许检查这两个属性?
$("select option").each(function () {
if ($(this).attr('data-disabled')) {
$(this).append('\'s account is disabled');
} else if ($(this).attr('data-locked')) {
$(this).append('\'s account is locked out');
} else if ($(this).attr('data-disabled') && $(this).attr('data-locked')) {
$(this).append('\'s account is disabled & locked');
};
});
最佳答案
您的第一个 if
是,这意味着您的 else
不会运行。只需将第三个 if
移至第一个即可。
关于javascript - 检查一个元素是否存在两个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24832597/