jquery判断对象是否为空并遍历对象的简单实例
javascript:
if(document.getElementById("target_obj_id")){
}else{
}
jquery:
因为$(“#target_obj_id”)不管对象是否存在都会返回object,所以以上方法不行
1.
vartarget_obj=jQuery('#target_obj_id');
if(target_obj.length>0){//如果大于0标识id为target_obj_id的对象存在,否则不存在
}else{
}
2、
if(target_obj[0]){
}else{
}
3.$.isEmptyObject({})//true
$.isEmptyObject({foo:"bar"})//false
//判断并遍历每个对象
if($("#t_specialsearchselect").length<=0){
alert("对象为空");
}else{
//console.log($("#t_specialsearchselect")[0]);
$("#t_specialsearchselect").each(function(){
//alert($(this));
console.log($(this));
});
for(variin$("#t_specialsearchselect")){
console.log($("#t_specialsearchselect")[i]);
}
}
一步一个脚印,方便自己复习,该出手时就出手,有错误,一定要指正,非常感谢,共同进步!
以上就是小编为大家带来的jquery判断对象是否为空并遍历对象的简单实例全部内容了,希望大家多多支持毛票票~
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短