代码之家  ›  专栏  ›  技术社区  ›  SapphireSun

在SWFUpload中找不到占位符元素

  •  1
  • SapphireSun  · 技术社区  · 15 年前

    我正在尝试在我拥有的表单上实现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(); },
        });
    };
    

    targetElement = document.getElementById(this.settings.button_placeholder_id) || this.settings.button_placeholder;
    

    我试着看看发生了什么难以置信地, document.GetElementByID 返回null,而 $('#'+this.settings.button_placeholder_id)

    1 回复  |  直到 15 年前
        1
  •  0
  •   SapphireSun    15 年前

    <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(); },
        });
    }
    
    推荐文章