jQuery IE8 issue
IE8 throws error on 4th line.
jQuery('#list script').each(function() {
var script=document.createElement('script');
script.type='text/javascript';
jQuery(script).text(jQuery(this).text()); //Error in IE8 does the field editing
document.body.appendChild(script);
}).remove();
jquery er开发者_StackOverflow中文版ror in routine:
append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 ) {
this.appendChild( elem );
}
});
You don't have to recreate the script elements or do all of that explicit removing. You can simply do the following:
jQuery('#list script').appendTo('body');
how about using jquery a bit more...
jQuery('#list script').each(function() {
jQuery('<script type="text/javascript" />').text(jQuery(this).text()).appendTo(jQuery('body'));
}).remove();
why don't you use jquery all the way?
jQuery('#list script').each(function() {
jQuery('<script></script>')
.attr('type','text/javascript')
.text(jQuery(this).text())
.appendTo(jQuery('body'));
}).remove();
Guessing it is a security exception since you didn't list anything.
Though without the question explaining the exact line (in the jquery routine) and exact exception this is a mere stab in the dark.
It could be that you are accessing a script that is outside the page's domain and therefore will not allow you to access its text.
It could also be the way you create the script tag.
I'd suggest something a little more concise:
$('#list script').each(function() {
$('<script>').text($(this).text()).appendTo($(document.body));
})
.remove();
Note I left out the type on assuming you are using html5, if not you'll optionally want to put it in there
精彩评论