我的上传表单运行良好,但我想以编程方式更改设置,但出现错误。
Uploadify 是在 document.ready 上启动的,我正在尝试将 updateSettings 绑定(bind)到按钮单击(也在 document.ready 中完成)。我还尝试在 document.ready 之外使用 updateSettings 函数 - 实际上在按钮上或只是内联脚本来获得相同的错误。
错误是
Error: document.getElementById(a(this).attr("id") + "Uploader").updateSettings is not a function
我的代码目前看起来像
<script>
$(document).ready(function(){
$('#uploadify').uploadify({
'uploader' : 'uploadify.swf',
'script' : 'uploadify.php',
'cancelImg' : 'cancel.png',
'auto' : true,
'folder' : '/uploads'
});
$("#changeIt").click(function(){
$("#uploadify").uploadifySettings("folder","something_else");
});
});
</script>
<input type="file" name="uploadify" id="uploadify" />
<a id="changeIt" src="#">Change the upload dir</a>
就像我说的,我尝试在 document.ready 之外添加 uploadifySettings,我还尝试将其添加到 a 标签本身的 onclick 中,以获得相同的错误。我真的很感激任何帮助。
最佳答案
你的代码是错误的。 Uploadify 无法绑定(bind)到 <input type="file">
,仅到 <div/>
。请参阅 uploadify 站点中的文档和示例。
为了进行渐进增强,我有两个元素,<input type="file"/>
和一个空的<div/>
。然后在 JavaScript 代码中,我删除输入元素,然后初始化 uploadify。
<input type="file" name="uploadify" />
<div id="uploadify"></div>
<script type="text/javascript">
jQuery(function($){
$("input[name='uploadify']").hide().remove();
$("#uploadify").uploadify({UPLOADIFY_PARAM});
//a click handler to change uploadify param
//...
});
</script>
顺便说一句,我从不考虑 uploadify 中的文件夹参数。我在服务器端脚本中定义了上传文件夹。
关于javascript - 上传更新设置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2037605/