![](/img/trans.png)
[英]typeof a == 'undefined' vs typeof a === 'undefined'
[英]Typeof === 'undefined' issue
如果href的内容为空,则新手在这里尝试使用应该在console.log“ I un undefined”的功能。 我会非常感激,我将不胜感激... :-(
$(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");
}
它将处理任何虚假的值,如null
, undefined
, ""
。
.attr
返回普通对象。 它不会返回不确定的
这样尝试
$(document).ready(function () {
$('.facebook').each(function () {
var facebook = $(this).attr('href')
if (!facebook) {
console.log("I am undefined");
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.