【发布时间】:2015-05-06 07:57:01
【问题描述】:
新手在这里尝试使用这个功能,如果href的内容为空白,则应该控制台记录“我未定义”。我非常感谢任何帮助... :-(
$(document).ready(function () {
$('.facebook').each(function () {
var facebook = $(this).attr('href')
if (typeof facebook === "undefined") {
console.log("I am undefined");
}
});
});
【问题讨论】:
-
你的 facebook 变量是 null 不是未定义。检查 null 不是未定义。
-
使用 alert 或 console.log(facebook) 检查 facebook
-
好的,谢谢,会试试的
标签: javascript jquery html undefined typeof