我正在尝试在我拥有的表单上实现SWFUpload。但是,它没有识别占位符。我的代码在下面,有人可以帮忙吗?如果有帮助,我正在使用jQuery。
部首:
<script type="text/javascript" src="{{ MEDIA_URL }}/js/SWFUpload-2.5.0/swfupload/swfupload.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/SWFUpload-2.5.0/swfupload/swfupload.cookies.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/foo.js"></script>
<script type="text/javascript">
$(swfupload("{% url swfupload %}","{{ MEDIA_URL }}/js/SWFUpload-2.5.0/swfupload/swfupload.swf"));
</script>
体:
<div id="upload_btn"></div>
Javascript(foo.js):
swfupload = function(upload_url, flash_url) {
var swfupload_real = new SWFUpload({
debug: false,
upload_url: upload_url,
flash_url: flash_url,
button_placeholder_id: "upload_btn",
button_width: "40",
button_height: "16",
button_cursor: SWFUpload.CURSOR.HAND,
button_text: "Click",
file_size_limit: "20 MB",
file_dialog_complete_handler: function() { this.startUpload(); },
upload_complete_handler: function() { this.startUpload(); },
});
};
编辑:我尝试查看SWFUpload.js的源代码,发现在尝试查找元素时,它会这样做:
targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
我试着看看发生了什么,令人难以置信的是,document.GetElementByID
返回null而$('#'+this.settings.button_placeholder_id)
返回对象!我宁愿不修改库以使用另一个依赖。有谁知道为什么会这样?
答案 0 :(得分:0)
我的javascript已经满了。它解决了以下问题:
<script type="text/javascript">
upload_url = "{% url edit-story-swfupload %}";
flash_url = "{{ MEDIA_URL }}/js/SWFUpload-2.5.0/swfupload/swfupload.swf";
window.onload = swfupload_init;
</script>
swfupload_init = function() {
var swfupload = new SWFUpload({
debug: false,
upload_url: upload_url,
flash_url: flash_url,
button_placeholder_id: "upload_btn",
button_width: "40",
button_height: "16",
button_cursor: SWFUpload.CURSOR.HAND,
button_text: "Click",
file_size_limit: "20 MB",
file_dialog_complete_handler: function() { this.startUpload(); },
upload_complete_handler: function() { this.startUpload(); },
});
}