javascript - Typeof === 'undefined' 问题

标签 javascript jquery html undefined typeof

这里的新手尝试处理这个函数,如果 href 的内容为空,它应该在 console.log 中显示“我未定义”。我很感激任何帮助,因为我非常困...... :-(

$(document).ready(function () {
    $('.facebook').each(function () {
        var facebook = $(this).attr('href')
        if (typeof facebook === "undefined") {
            console.log("I am undefined");
        }
    });
});

最佳答案

它不会是未定义的,我想你可以使用:-

if (!facebook) {
    console.log("I am undefined");
}

它将处理任何虚假值,如 nullundefined""

关于javascript - Typeof === 'undefined' 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28869532/

相关文章:

javascript - 将 unicode 字符转换为字符串格式

javascript - 使用 javascript 创建元素时无法使 Bootstrap 工具提示工作

jquery - (jQuery) 如何在可滚动的 div 中的元素在滚动时出现动画?

jquery - 如何根据其中是否有表格来设置 div 的大小?

html - 从下往上堆叠元素

javascript - 返回数据后如何在 AngularJs 中链接多个方法

javascript - parseInt % 和 px 问题

javascript - 如何在验证失败时保留输入表单值 Spring MVC

html - div 入侵其他 div 空间?

javascript - 过滤键的最佳方法