jquery attr() 在 IE 中不起作用 [英] jquery attr() do not work in IE

查看:39
本文介绍了jquery attr() 在 IE 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jquery 做一些事情,我使用 attr() 方法来获取 id 属性,它在 Chrome 和 Firefox 中运行良好,但在IE9和Opera,部分代码如下:

I use jquery to do some thing, and I use attr() method to get the id attribute, and it works well in Chrome and Firefox, but not in IE9 and Opera, some of the code is like:

parent = $(this).parents('.every_note');        
loan_id = parent.attr('id');

在行中

loan_id = parent.attr('id');

Opera 说:未处理的错误:'parent.attr' 不是函数,并在 IE 中说:不支持 attr() 方法或属性.

Opera said: Unhandled Error: 'parent.attr' is not a function, and in IE said: does not support attr() method or attribute.

但是如果我在浏览器的控制台中测试它,我可以使用这个方法,所以谁能告诉我为什么?谢谢

But i can use this method if I test it in the browser's console , so anyone can tell me why? thanks

推荐答案

有时 IE 不喜欢$"而jQuery"对我有用.在较旧的 IE 中,全局变量与 jQuery 结合存在另一个问题.

Sometimes IE does not like the "$" while "jQuery" does work for me. In older IEs there is another problem with global vars in combination with jQuery.

试试:

var parent = jQuery(this).parents('.every_note');        
var loan_id = parent.attr('id');

关于 jQuery-IE 问题的文章(德语)

这篇关于jquery attr() 在 IE 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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