0.id为null或不是对象,parentElement的parentElement和ie8
0.id is null or not an object, parentElement of the parentElement and IE 8
我使用以下3行代码在我的web应用程序。
selected_build = event.currentTarget.parentElement.parentElement.id;
var jselect = $( "#" + selected_build + " .roomc" ).children(".room");
selected_room = jselect[0].id;
这在大多数浏览器中都有效,但在ie8中我得到错误
'0.id' is null or not an object
指向第三行代码。我认为这与parentElement只在元素上工作有关,但我似乎无法弄清楚。
我认为这与parentElement只在元素上工作有关…
如果IE8没有parentElement
,因为根据定义你处理的是event.currentTarget
的元素,你可以安全地使用parentNode
来代替。
但是当你使用jQuery 无论如何,为什么不…使用jQuery吗?
selected_build = $(event.currentTarget).parent().parent().attr("id");
if (selected_build) {
var jselect = $("#" + selected_build + " .roomc").children(".room");
selected_room = jselect.attr("id");
if (selected_room) {
// ... use it
}
}
请注意,我使用.attr("id")
来获得id
。这是因为如果jQuery集合为空, .attr("id")
给出的是undefined
,而[0].id
给出的是错误。
和actually 本;除了在selected_room
:
id
s。selected_room =
$(event.currentTarget)
.parent().parent()
.find(".roomc > .room")
.attr("id");
if (selected_room) {
// ... use it
}
…我敢打赌,肯定有办法把事件联系起来,这样我们就可以避免脆弱的.parent().parent()
。但如果没有看到结构,就不可能提出什么建议。
相关文章:
- Recaptcha在IE7和IE8中不起作用
- Joomla Gantry Framework ie8 LESS/CSS
- 为什么jQuery 1.8不能在IE8和InternetExplorer9中使用?(截至2012年9月的IE9最新版本)
- 在IE8中不起作用的元素上触发单击事件
- 谷歌地图v3标记没有显示ie8和9
- 数据-在IE8中不起作用
- 在IE8上使用jQuery克隆HTML5元素和事件
- 仅IE8 html文本框中的字符
- getComputedStyle替换:currentStyle(IE8/7)不起作用
- IE8更改文本区域上的事件侦听器不工作
- 如何确定相对较新版本的IE的高度和宽度(IE8不喜欢从JavaScript设置这种样式吗?
- jquery validate 1.8.1”;jQuery"是未定义的错误IE8
- 如何在IE8及以前版本中处理mousemove
- .Net webApi ISO日期时间和IE8
- javascript表单字段submit:Object dos'在IE8中不支持此属性或方法
- 我可以使用什么Javascript或Jquery库来处理带有IE8的GANTT图表
- IE8 jquery ajax头请求不起作用
- 在IE8中创建脚本标记
- javascript/jQuery:在title中添加换行符——在IE9中有效,但在IE8中无效
- 0.id为null或不是对象,parentElement的parentElement和ie8