我这里面有一个JS,主要的功能就是批量上传图片,我刚选择完图片的时候现在就自动触发上传的功能了,我现在想放在一个事件里面,只有触发这个事件才可以执行上传的功能,但是现在还有一个问题,在页面刚加载的时候需要执行这个JS的,哪位仁兄帮我看一下呀,感谢!
<script type="text/javascript">
<!--
var swfu;
window.onload = function() {
var settings = {
flash_url : "swfupload/swfupload.swf",
//upload_url: "http://localhost:8080/zhai2/upload.asp", // Relative to the SWF file
post_params: {"PHPSESSID" : "<%randomize:response.write replace(replace(replace(replace(now&rnd(),"-",""),":","")," ",""),".","")%>"},
file_size_limit : "1 MB",
file_types : "*.gif;*.bmp;*.jpg;*.jpeg;*.png",
file_types_description : "All Files",
file_upload_limit : 10,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,

// Button settings
button_image_url: "images/filebotton.png", // Relative to the Flash file
button_width: "65",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,

// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
     }; //-->
</script>

解决方案 »

  1.   

    这个JS不是在页面刚加载的时候要调用FLASH在页面显示的,然后我点击这个FLASH进行批量上传图片,还是调用这个JS的,但是我想在上传照片的时候用一个按钮去触发这个JS,而不是自动就执行了
      

  2.   


    window.onload = function(){
        var settings = {
            xxxx
        };
        var btn = $('button的ID');
        btn.onclick = function(){
            new SWFUpload(settings);
            this.style.display = 'none';
        } 
    }
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <head>
    <title>test</title>
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="swfupload/swfupload.js"></script>
    <script type="text/javascript" src="js/swfupload.queue.js"></script>
    <script type="text/javascript" src="js/fileprogress.js"></script>
    <script type="text/javascript" src="js/handlers.js"></script>
    <script type="text/javascript">
    <!--
    var swfu;
    window.onload = function() {
    var settings = {
    flash_url : "swfupload/swfupload.swf",
    //upload_url: "http://localhost:8080/zhai2/upload.asp", // Relative to the SWF file
    post_params: {"PHPSESSID" : "<%randomize:response.write replace(replace(replace(replace(now&rnd(),"-",""),":","")," ",""),".","")%>"},
    file_size_limit : "1 MB",
    file_types : "*.gif;*.bmp;*.jpg;*.jpeg;*.png",
    file_types_description : "All Files",
    file_upload_limit : 10,
    file_queue_limit : 0,
    custom_settings : {
    progressTarget : "fsUploadProgress",
    cancelButtonId : "btnCancel"
    },
    debug: false,

    // Button settings
    button_image_url: "images/filebotton.png", // Relative to the Flash file
    button_width: "65",
    button_height: "29",
    button_placeholder_id: "spanButtonPlaceHolder",
    button_text: '',
    button_text_style: ".theFont { font-size: 16; }",
    button_text_left_padding: 12,
    button_text_top_padding: 3,

    // The event handler functions are defined in handlers.js
    file_queued_handler : fileQueued,
    file_queue_error_handler : fileQueueError,
    file_dialog_complete_handler : fileDialogComplete,
    upload_start_handler : uploadStart,
    upload_progress_handler : uploadProgress,
    upload_error_handler : uploadError,
    upload_success_handler : uploadSuccess,
    upload_complete_handler : uploadComplete,
    queue_complete_handler : queueComplete // Queue plugin event
    };
    swfu = new SWFUpload(settings);
         }; //-->
    </script>
    </head>
    <body><div id="content">
    <form id="form1" action="index.asp" method="post" enctype="multipart/form-data">
    <p>点击“浏览”按钮,选择您要上传的文档文件后,系统将自动上传并在完成后提示您。</p>
    <!-- <p style="color:#F00">请勿上传包含中文文件名的文件!</p> -->
           <!--  <p style="height:30px; line-height:30px; vertical-align:middle">原文件名:<input type="text" name="text1" id="text1" style="vertical-align:middle;">&nbsp;保存路径:<input type="text" name="text2" id="text2" style="vertical-align:middle;"></p> -->
    <div class="fieldset flash" id="fsUploadProgress">
    <span class="legend">快速上传</span>
      </div>
    <div id="divStatus">0 个文件已上传</div>
    <div>
    <span id="spanButtonPlaceHolder"></span>
    <input id="btnCancel" type="button" value="取消所有上传" onclick="swfu.cancelQueue();" style="margin-left: 8px; font-size: 9pt; height: 29px;" />
    </div>
    </form>
    </div>
    </body>
    </html>
      

  4.   

    upload_url: "http://localhost:8080/zhai2/upload.asp", // Relative to the SWF file
    要把这行的注释去掉的!
    这是一个SWFupload+JS+ASP批量上传图片的例子
      

  5.   

    感谢大家的回复,不过4楼的那个方法还是有点问题的,因为在页面刚加载的情况下需要调用swfu = new SWFUpload(settings);在页面刚加载的时候要初始化这个对象的。