3

I'm trying to use Valum's file upload script ( http://valums.com/ajax-upload/ ) to allow the creation of links that allow file uploads.

I'm using the jQuery library.

It's simple to get one link on a page to work using the standard documentation, but now I want to be able to catch all links of a given class rather than statically assigning to a given element.

Futhermore my site uses Ajax pageloads so I need to be able to somehow assign the uploader to new Ajax loaded content.

The envisaged use is to allow creating a link like this in an Ajax loaded page and have it trigger the uploader:

<a href="#" class="uploader">Upload a file</a>

My first thought is to use the jQuery live() method to try bind the class, but I can't find a suitable event to trigger on.

Has anybody had experience with this sort of issue?

4

1 回答 1

0

<input type="file">不,不幸的是,这并不容易。由于一些安全问题,IE(甚至是 IE9!)只是不允许您使用“摆弄”这个元素来汇总表单 - 当人为地在其上引发“单击”、“更改”或任何其他事件时。

所以这个插件的工作方式不同。不是创建一个事件处理程序来“重新路由”用户单击到某个动态创建的文件输入元素,而是围绕作为其目标的链接创建包装器结构 - 并且文件输入就插入那里,隐藏得足以让用户看不到它 - 但足以让浏览器注册点击它(查看源代码中的此方法和本文以获取详细信息)。

底线是,你不能在这里使用事件处理委托:唯一明智的方法是用该插件包装新创建的元素。

于 2012-12-24T18:12:51.173 回答