jquery - IE7 - issue with javascript -
i have issue on old ie explorers js code:
var elements = [ {'name':'manuscript_file', 'filetype':/(\.|\/)(doc|docx|txt|odt|zip|rar|rtf|gz|tar|bz2|bz|7z|tex)$/i}, {'name':'presentation_file', 'filetype':/(\.|\/)(pdf)$/i}, {'name':'figures_file', 'filetype':/(\.|\/)(pdf|png|jpg|gif|zip|rtf|eps)$/i}, {'name':'graphical_file', 'filetype':/(\.|\/)(pdf|png|jpg|gif)$/i}, {'name':'supplementary_file', 'filetype':/(\.|\/)(zip)$/i}, {'name':'non_published_material', 'filetype':/(\.|\/)(doc|docx|zip|pdf)$/i}, ] , url = $('form').attr('action'); $.each(elements, function(i, element) { $('#form_' + element.name).val(''); $('#form_' + element.name).prev('button').removeattr('disabled') ...
on line with
$('#form_' + element.name).val('');
ie7 telling me
message: 'name' null or not object
any idea? thx.
the problem here trailing comma in array of elements. net explorer 7 incorrectly interpreting value right of lastly comma. makes length n+1, causing jquery evaluate null value on lastly cycle:
class="lang-js prettyprint-override">var elements = [ { 'name': 'manuscript_file' }, { 'name': 'non_published_material' }, <-- ]
you can see confirmed looping on 2 arrays; 1 trailing comma, , 1 without. open http://jsfiddle.net/jonathansampson/mqntjbky/show/ in ie 7 confirmation.
class="lang-js prettyprint-override">(function () { var elements = [ { name: "foo" }, { name: "bar" } ]; var alternatives = [ { name: "fizz" }, { name: "buzz" }, ]; // $.each not throw exception $.each( elements, function create ( i, element ) { seek { $( "<div></div>" ).text( element.name ).appendto( "body" ); } grab ( e ) { alert( "top fail: " + e.message ) } }); // $.each throw exception $.each( alternatives, function create ( i, element ) { seek { $( "<div></div>" ).text( element.name ).appendto( "body" ); } grab ( e ) { alert( "bottom fail: " + e.message ) } }); }());
note below "top fail" message never raised, in block looping collection lacks trailing comma. "bottom fail" message, however, in affected block, , raised during iteration.
javascript jquery internet-explorer internet-explorer-7
No comments:
Post a Comment