Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IE7-javascript问题_Javascript_Jquery_Internet Explorer_Internet Explorer 7 - Fatal编程技术网

IE7-javascript问题

IE7-javascript问题,javascript,jquery,internet-explorer,internet-explorer-7,Javascript,Jquery,Internet Explorer,Internet Explorer 7,我只对使用此js代码的旧IE探索者有一个问题: 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',

我只对使用此js代码的旧IE探索者有一个问题:

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')
    ...
在线

 $('#form_' + element.name).val('');
IE7告诉我

Message: 'name' is null or not an object

有什么想法吗?Thx.

这里的问题是元素数组中的尾随逗号。Internet Explorer 7错误地解释了最后一个逗号右侧的值。这使得长度为n+1,从而导致jQuery在其最后一个周期中计算空值:

var元素=[
{“姓名”:“手稿档案”},

{'name':'non_published_material'},如果使用
element.getAttribute('name')
而不是
element.name
,会发生什么?我不知道为什么,但在我的例子中,在第一次迭代中,变量
element
是数组
elements
本身。只是添加了
if(element)
以消除错误。您使用的是什么版本的jQuery?是的,@PaulS.said或,作为另一种$(element).attr('name')使用的是什么?我手头没有IE 7。它显示了什么?
element
在上次调用中是
未定义的
?回答很好,很有魅力。非常感谢。