使用诱饵破坏了我在 IE 上的上传。为什么?
我正在使用 Valums AJAX Uploader,它工作得很好,即使在 IE 中也是如此。
当我尝试使用诱饵来隐藏 Valums 标记时,就会出现问题。
$('.control.addphoto:not(.controlactive)').live('click', function(){
$('#upload input[type=file]').click();
});
因此,真正的输入是隐藏的,但单击我的控件会激活它。 “选择文件”对话框在 IE 中显示得很好,但一旦我单击“确定”,文件上传就会失败(它甚至无法到达服务器)。当我不使用诱饵时(即当我直接单击输入时),它工作得很好。
Chrome 和 Firefox 中一切正常。
为什么会发生这种情况?我无法理解,因为它只是一个诱饵,它调用的是实际输入。有什么线索吗?有什么办法可以让诱饵变得更加“透明”?
obs:刚刚发现诱饵在 Opera 上不起作用(不打开对话框)。同样,直接单击输入即可正常工作。因为我使用的是jquery(应该是跨浏览器),所以这不应该起作用吗?
编辑
Opera 实际上本质上不允许通过诱饵触发输入行为。
使用 Kevin B 的替代方案,我已经能够解决我的问题。另一方面,我仍然不知道为什么 IE 会发生这种情况,并且为了知识而保留这个问题。
I'm using Valums AJAX Uploader and it works just fine, even in IE.
The problem appears when i try to use a decoy to hide Valums markup.
$('.control.addphoto:not(.controlactive)').live('click', function(){
$('#upload input[type=file]').click();
});
so, the real input is hidden but clicking my control activates it. The "choosing file" dialog gets displayed just fine in IE but once i click OK the file upload fails (it doesn't even get to the server). When I doesn't use the decoy (i.e. when i click in the input directly) it works just fine.
Everything works fine in Chrome and Firefox.
Why is this happening? I couldn't understand since it's just a decoy and it's calling the actual input. Any clue? Any way to make the decoy more "transparent"?
obs: just found out that the decoy isn't working on Opera (doesn't opens the dialog). Again, clicking directly on the input works fine. Shouldn't this be working since i'm using jquery (wich is suposed to be crossbrowser)?
EDIT
Opera actually doesn't allow triggering the input behavior through a decoy by nature.
Using Kevin B's alternative i've been able to solve my problem. On the other hand i still don't know why that happened with IE and will keep this question opened for the sake of knowledge.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决此问题的一种方法是使触发元素不可见,但不隐藏,例如为其提供与其后面的元素相同的背景颜色。然后,您可以将其放置在“诱饵”之上,这样看起来就像您在单击诱饵,而实际上您是在单击文件输入。
One solution to this is to make the trigger element invisible, but not hidden, such as giving it the same background color as the element behind it. You can then place it on top of the "decoy" so that it will look like you are clicking on the decoy, while you are actually clicking on the file input.