用JS判断一个html元素是否存在的五种方法
2010-05-14 10:57
567 查看
用javascript判断一个html元素是否存在的五种方法:
1. 判断表单元素是否存在(一)
if("periodPerMonth" in document.theForm){
return true;
}else{
return false;
}
2. 判断页面元素是否存在
if(document.getElementById("XXX")){
//存在
}
3. 判断表单元素是否存在(二)
if(document.theForm.periodPerMonth){
//存在
}
或
if(typeof(document.theForm.periodPerMonth)=="object"){
//存在
}
4. 判断表单是否存在
if(document.theForm){
//存在
}
5.用Jquery写脚本
if ( $("#someID").length > 0 ){
$("#someID").text("hi");
}
1. 判断表单元素是否存在(一)
if("periodPerMonth" in document.theForm){
return true;
}else{
return false;
}
2. 判断页面元素是否存在
if(document.getElementById("XXX")){
//存在
}
3. 判断表单元素是否存在(二)
if(document.theForm.periodPerMonth){
//存在
}
或
if(typeof(document.theForm.periodPerMonth)=="object"){
//存在
}
4. 判断表单是否存在
if(document.theForm){
//存在
}
5.用Jquery写脚本
if ( $("#someID").length > 0 ){
$("#someID").text("hi");
}
相关文章推荐
- 用JS判断一个html元素是否存在的五种方法
- 用JS判断一个html元素是否存在的五种方法
- 用JS判断一个html元素是否存在的五种方法
- 用javascript判断一个html元素是否存在的五种方法:
- 用JavaScript判断一个html元素是否存在的几种方法
- 2017-04-05js判断一个元素是否存在的方法
- 通过JS,Jquery判断某个字符在一个字符串中是否存在的方法
- 如何在前端用js判断一个元素在一个数组中是否存在
- js 判断一个元素是否在页面中存在
- 利用JS判断图片,文件是否存在的几种方法
- js 判断一个元素是否在页面中存在
- 判断一个指定的Service是否存在的方法
- 用js判断用户名cookie是否存在的正确方法
- js判断一个变量或对象是否存在
- js判断某个方法是否存在实例代码
- js中定义一个变量并判断其是否为空的方法
- 当获取相似数据时,使用不同方法调用不同sp,但是使用同一个方法去用IIDataReader或者SqlDataReader读取数据时需要判断column name是否存在。
- js判断一个字符串是否包含一个子串的方法
- JS判断图片是否存在的几种方法
- JS判断一个数组中是否有重复值的三种方法