2012-12-19 31 views
1

下面的代码添加了一个链接上传字段。对于每一个新的点击它显示了一个新的上传字段的形式最多,共5有在Chrome中没有错误等IE8不支持jQuery变量内部选择器?

我想知道什么是错与下面的线,因为它似乎在脚本运行良好在其他浏览器上,但在IE8上它会抛出一个错误:Object doesn't support this action。你能建议替代的代码吗?

<div id="edit-submitted-file1-ajax-wrapper" style="display: block;"> 
    //upload field here 
</div> 
<a id="addmore" href="#">[+] Add more</a> 

<div id="edit-submitted-file2-ajax-wrapper" style="display: block;"> 
    //upload field here 
</div> 

<div id="edit-submitted-file3-ajax-wrapper" style="display: block;"> 
    //upload field here 
</div> 

first = $('.webform-client-form').find('div[id$="-ajax-wrapper"]').first(); 
     first.after('<a id="addmore" href=#>[+] Add more</a>'); 
     $('.webform-client-form').find('div[id$="-ajax-wrapper"]').each(function(){ 
      $(this).hide(); 
      first.show(); 
     }); 

var c = 0; 
$('#addmore').bind('click', function(e) { 
    //HERE BELOW IS THE LINE WITH ERROR 
    item = $('#edit-submitted-file'+ c +'-ajax-wrapper'); 
    item.show(); 
    ++c; 
    if (c == 5) { 
     $('#addmore').hide(); 
     return false; 
    } 
}); 
+0

什么目的,什么样的行动,那么你的HTML是什么样子?运行时你真的看过调试器吗? – Jamiec

+0

这是什么?项是一个有效的jQuery元素?如果没有,你会得到对象不支持错误,因为项目将最终为空。 – ryadavilli

+0

什么是变量'c',一些循环计数器? –

回答

1

更改此

item = $('#edit-submitted-file'+ c +'-ajax-wrapper'); 

这个

var item = $('#edit-submitted-file'+ c +'-ajax-wrapper'); 

http://jsfiddle.net/fJ3EG/2/

+0

不幸的是,没有骰子。 :( – Kandinski

+0

@FarcasO。奇怪,我得到了相同的结果。它正常工作与变种确保您的代码不被缓存。 –

+0

你是正确的VAR是问题 – Kandinski

0

你可能使用这个词“项目”在你的HTML某处之前。声明你的变量为var item,问题应该解决。

见#2这个早期的岗位:

My guess is that you have something on your page that has either the name or id "item", and so that's becoming a property of window because IE does that (...)

ie, javascript and 'item' as a variable name