js中null和 document.getElementById("userId")小结
2014-01-14 14:26
671 查看
1、IE8中, document.getElementById("userId").value;
获得不了对象值,把函数写在变量声明后面即可。
顺序如下:
<body>
<input type="text" name="userId" id="userId" tabindex="3"/>
<script type="text/javascript">
function checkInput() {
var userId = document.getElementById("userId");
}
</script >
</body>
此时,可以获得其值,如果是放在<head></head>之间,取不到。
2、null的判断
var userId = document.getElementById("userId");
var isNull=(!userId && typeof userId != "undefined" && userId != 0);
typeof exp != "undefined" 排除了 undefined; exp != 0 排除了数字零,!exp排除 false。
3、360浏览器中,
3.1 如下将获得null,虽然在IE中正常,但在360中由于变量没有ID值,故会是null.
<input type="text" name="userId" tabindex="3"/>
var userId = document.getElementById("userId"); //null
3.2 加上ID后,可以获得。
<input type="text" name="userId" id="userId" tabindex="3"/>
var userId = document.getElementById("userId"); //不再是null
获得不了对象值,把函数写在变量声明后面即可。
顺序如下:
<body>
<input type="text" name="userId" id="userId" tabindex="3"/>
<script type="text/javascript">
function checkInput() {
var userId = document.getElementById("userId");
}
</script >
</body>
此时,可以获得其值,如果是放在<head></head>之间,取不到。
2、null的判断
var userId = document.getElementById("userId");
var isNull=(!userId && typeof userId != "undefined" && userId != 0);
typeof exp != "undefined" 排除了 undefined; exp != 0 排除了数字零,!exp排除 false。
3、360浏览器中,
3.1 如下将获得null,虽然在IE中正常,但在360中由于变量没有ID值,故会是null.
<input type="text" name="userId" tabindex="3"/>
var userId = document.getElementById("userId"); //null
3.2 加上ID后,可以获得。
<input type="text" name="userId" id="userId" tabindex="3"/>
var userId = document.getElementById("userId"); //不再是null
相关文章推荐
- document.getElementById("idName")用js方法获取元素,则设定风格属性的方法为
- JS中“null'document.getElementById为空或不是对象” 的解决办法
- JS中“null'document.getElementById为空或不是对象” 的解决办法
- 调用js报错:try { document.getElementById("").SetReturnValue(__flash__toXML(MY_FUNCTION(
- 母版页导致js 获取不到'document.getElementById("...").value 或 document.all("...").value
- .net 使用模板页,JS使用document.getElementById("")得到null的解决办法
- document.getElementById("radFs")对象为空,js判断对象是否存在?
- 一直认为的Jquery中的$("#id")和document.getElementByID("id")是不一样的
- document.getElementById("parentControl") 根据ID来获取一个控件
- 在document.getElementById("oDiv").innerHTML="JS执行问题";
- label的Visible="False"时用alert(document.getElementById("aa").innerText);会报错,为什么呢?
- js节省document.getElementById("xxx")的方法
- js中的document.getElementById("id").style.property="值" 的用法
- document.getElementById("xx").style.xxx中的所有属性是什么
- document.getElementById("")和document.getElementsByName()和document.getElementsByTagName()有什么区别
- js判断document.getElementByid("")获得的对象是否存在
- 为什么不能直接通过document.getElementById("<%= txtCard.ClientID %>")
- document.getElementById("divv").style.display = 'none';
- jsp页面javascript中用document.getElementById(" ").value无法获取相应text的值
- document.getElementById(" ") 为空或不为对象