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

查看:635
本文介绍了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');

行中的

in the line

loan_id = parent.attr('id');

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

但是我可以使用这种方法,如果我在浏览器的控制台测试它,
所以任何人都可以告诉我为什么?谢谢

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-problems(德语)的文章

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

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