下面的代码添加了一个上传字段的链接。对于每一次新点击,它都会在表单中显示一个新的上传字段,最多 5 个。Chrome 等中没有错误。
我想知道下面这行有什么问题,因为该脚本似乎在其他浏览器上运行良好,但在 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>
ETC
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;
}
});