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