firstElementChild在Internet Explorer 7中不起作用...我的选择是什么? [英] firstElementChild doesn't work in Internet Explorer 7...what are my options?

查看:98
本文介绍了firstElementChild在Internet Explorer 7中不起作用...我的选择是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的JavaScript:

Consider the JavaScript below:

var v;
if (this.children.length > 0) {
    v = this.firstElementChild.value;
}

这适用于现代版本的FireFox和Chrome,但 this.firstElementChild.value 在Internet Explorer 7-8中引发异常。我还有另一种方法可以让它适用于所有浏览器吗?

This works in modern versions of FireFox and Chrome but this.firstElementChild.value throws an exception in Internet Explorer 7-8. Is there another way for me to get this to work for all browsers?

我选择了以下内容:

v =(this.firstElementChild || this.children [0] || {})。value - 谢谢对所有人来说。

v = (this.firstElementChild || this.children[0] || {}).value --Thanks to all.

推荐答案

我不知道,也许 this.children [0] .value

这篇关于firstElementChild在Internet Explorer 7中不起作用...我的选择是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆