今天用到判断对象是否存在的问题,发现用jquery 定位对象与 document.getElementById的区别
我们用alert来监测不存在的name对象时发现:
- alert($("#name"));//return object
- alert(document.getElementById('name'))//return null
- alert($("#name").val());// return undefined
最后判断页面对象是否存在的其中几种方法:
1.jquery语法:$("#name").val() == undefined
2.document.getElementById('name') == null
这里不推荐document.all的方法,它只被ie识别