![](/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.