如果我尝试获取{
,:(: "",
,:): "",
,:-(: "",
,:-): "",
0:): "",
0:-): "",
8-): "",
:"): "",
:$: "",
:'(: "",
:'): "",
:'-(: "",
:'-): "",
:'-D: "",
:'D: "",
:(: "",
:): "",
:*: "",
:,'(: "",
:,'-(: "",
:,(: "",
:,): "",
:,-(: "",
:,-): "",
:,-D: "",
:,D: "",
:-"): "",
:-$: "",
:-(: "",
:-): "",
:-*: "",
:-/: "",
:-@: "",
:-D: "",
:-o: "",
:-O: "",
:-P: "",
:-S: "",
:-Z: "",
:-|: "",
:/: "",
:@: "",
:D: "",
:o: "",
:O: "",
:P: "",
:s: "",
:z: "",
:|: "",
;(: "",
;): "",
;-(: "",
;-): "",
]:): "",
]:-): "",
B-): "",
o:): "",
O:): "",
O:-): "",
o:-): "",
X-): "",
x-): ""
}
且文档中根本没有p标记,则变量仍然不为空,但仍有一些内容。如果我做var allPTags = document.getElementsByTagName("p");
,它就不会发出警报;如何比较空值?
答案 0 :(得分:1)
试试这个:
var allPTags = document.getElementsByTagName("p");
if(allPTags.length>0){
alert("stackoverflow"); // your message if any P tag is present.
}
答案 1 :(得分:1)
因为结果是一个空数组,所以你应该执行以下操作:
function showParentDiv()
{
//I need a svg onload event is fired after its parent div is shown.
//End function
$("#parent_div").show();
}
答案 2 :(得分:1)
试试这个:
var allPTags = document.getElementsByTagName("p");
var allPTagsCount = allPTags.length;
if(allPTags !== "") {
alert(something);
}