jquery attr() do not work in IE

最后都变了- 提交于 2020-01-05 22:45:16

问题


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 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


回答1:


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.

Try:

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

Article about jQuery-IE-problems (german)




回答2:


Use

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


来源:https://stackoverflow.com/questions/12652284/jquery-attr-do-not-work-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!