上传功能无法使用document.forms [0] .submit(),当我将其作为type = submit时,它正在工作

时间:2014-01-16 11:05:01

标签: javascript html dojo

<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.10.3/dojo/dojo.js"></script>
<form method="post" action="FileUpload" id="myForm" enctype="multipart/form-data">
  <fieldset>
    <legend>Form Post Test</legend>

    <!-- <input   type="file" multiple="true" id="uploader2" name="uploadedfile" class="fileInput" data-dojo-attach-point="_fileInput" 
    				dojoType="dojox.form.Uploader" label="Select Some Files"> 
    				<input
    				type="text" name="album" value="Summer Vacation" /> <input
    				type="text" name="year" value="2011" /> 
    				<input type="button" id="clear" label="Clear" value="clear"/>
    				<input type="submit"
    				label="Submit" value="submit1234" />
    			<div id="files" dojoType="dojox.form.uploader.FileList"
    				uploaderId="uploader1"></div>-->

    <input name="uploadedfile" multiple="true" type="file" id="uploader" data-dojo-type="dojox.form.Uploader" data-dojo-props='label:"Select Some Files"' />
    <input type="submit" label="Submit" data-dojo-type="dijit.form.Button" />
    <div id="files" data-dojo-type="dojox.form.uploader.FileList" data-dojo-props='uploaderId:"uploader"'></div>
    <input type="submit" label="Submit" value="htmlsubmit">
    <input type="button" label="Submit" value="buttonsubmit" onclick="document.forms[0].submit();" />

在上面的代码中,当我点击htmlsubmit按钮时,所选文件正在上传。但是当我点击buttonsubmit时,文件没有上传。

我想了解文件上传功能时type="submit"type="button"之间的区别

1 个答案:

答案 0 :(得分:0)

尝试更改此内容:

<input  name="uploadedfile" multiple="true"  type="file" id="uploader"
    data-dojo-type="dojox.form.Uploader" data-dojo-props='label:"Select Some Files"' />        
    <input type="submit" label="Submit" data-dojo-type="dijit.form.Button" />
    <div id="files" data-dojo-type="dojox.form.uploader.FileList"
        data-dojo-props='uploaderId:"uploader"'></div> 
<input type="submit" label="Submit" value="htmlsubmit" >
        <input type="button" label="Submit" value="buttonsubmit" onclick="document.forms[0].submit();"/>

为:

<input  name="uploadedfile" multiple="true"  type="file" id="uploader"
    data-dojo-type="dojox.form.Uploader" data-dojo-props='label:"Select Some Files"' />  
    <div id="files" data-dojo-type="dojox.form.uploader.FileList"
        data-dojo-props='uploaderId:"uploader"'></div> 
        <input type="submit" label="Submit" value="htmlsubmit" id="htmlsubmit">
        <input type="button" label="Submit" value="buttonsubmit" id="buttonsubmit" onclick="htmlsubmit.click();"/>