<input id="Submit1" type="submit" value="submit" />
放了个最简单的客户端submit我程序里动态生成<input type="file"/>生成好以后,再点击submit按钮的话,生成了几个file,就要按几次submit,否则没有反应就比如说,添加了两个上传文件,想要submit就要点3回按钮,头两下没有任何反应,即不提交,也不出错。
放了个最简单的客户端submit我程序里动态生成<input type="file"/>生成好以后,再点击submit按钮的话,生成了几个file,就要按几次submit,否则没有反应就比如说,添加了两个上传文件,想要submit就要点3回按钮,头两下没有任何反应,即不提交,也不出错。
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1" enctype="multipart/form-data">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTcwMDAwMDI4Mg9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRk9EYK7D757JP5q5j/LeV7fDD/SNo=" />
</div> <div><script language="javascript" type="text/javascript">
// <!CDATA[
var numFileIndex = 0;function ButtonAccessoriesAdd_onclick()
{
var numlistboxLength;
var strFilePath; // save filepath
var objNewFile = document.createElement("input"); // create a new element <input/>
objNewFile.type = "file"; // edit type="file" <input type="file" />
objNewFile.name = "fileUpload"+ numFileIndex;
objNewFile.id = "fileUpload"+ numFileIndex; // add a id <input type="file" id="fileUpload1" />
objNewFile.style.display = "none"; // hidden it
numFileIndex = numFileIndex + 1;
document.getElementById("divFileUpload").appendChild(objNewFile); // append the <input type="file"/> to divFileUpload
document.getElementById(objNewFile.id).click(); //click the new file element
strFilePath = document.getElementById(objNewFile.id).value; //get file path
numlistboxLength = document.getElementById('ListBoxAccessories').options.length; for(var i = 0;i < numlistboxLength;i++)
{
//check same name file
if(document.getElementById('ListBoxAccessories').options[i].value == strFilePath)
{
strFilePath = "";
break;
}
}
if(strFilePath != "")
{
//selected a file and add to listbox
document.getElementById('ListBoxAccessories').options[numlistboxLength]
= new Option(strFilePath,strFilePath) ;
}
else
{
//del the invalid file
document.getElementById('divFileUpload').removeChild(document.getElementById(objNewFile.id));
}
}function ButtonAccessoriesDel_onclick()
{
var intIndex; //selected file index
var strFilePath; //upload file full path
intIndex = document.getElementById('ListBoxAccessories').selectedIndex; //get selected file index
if(intIndex >= 0)
{
//selected item is not null
strFilePath = document.getElementById('ListBoxAccessories').options[intIndex].value; //save file full path
document.getElementById('ListBoxAccessories').options[intIndex] = null; //del it in listbox
for(var i=0;i<500;i++)
{
if(document.getElementById("fileUpload"+i) != null)
{
if(document.getElementById("fileUpload"+i).value == strFilePath)
{
//delete selected file
document.getElementById('divFileUpload').removeChild(document.getElementById("fileUpload"+i));
return true;
}
}
}
}
}
// ]]>
</script>
<table border="0" width="950px" cellspacing="3" cellpadding="0">
<tr>
<td width="950px" bgcolor="#FFFFFF" colspan="4" height="14" >
<table border="0" width="950px" cellpadding="0" cellspacing="0">
<tr>
<td width="948px" height="14px" colspan="2"><font class="tab_blc_font">「</font><font class = "small_font">*</font><font class="tab_blc_font">」</font><font class = "small_font">のついている項目は必ずご入力ください</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="label_td"><font> タイトル </font><font class = "small_font">*</font></td>
<td width="810px" colspan="3" height="19px"> <input name="TextBoxTitle" type="text" maxlength="50" id="TextBoxTitle" class="long_text" style="width:350px;" /></td>
</tr>
<tr>
<td class="label_td"><font> 本文 </font><font class = "small_font">*</font></td>
<td style="height:76px; width:810px" valign="top" rowspan="2" colspan="3" > <textarea name="TextBoxMemo" rows="5" cols="20" id="TextBoxMemo" style="width:739px;"></textarea></td>
</tr>
<tr>
<td style="height:57px; width:140px" bgcolor="#FFFFFF"></td>
</tr>
<tr>
<td class="label_td"><font> 添付資料</font></td>
<td width="400px" height="57px" rowspan="4" colspan="2" valign="top">
<select size="4" name="ListBoxAccessories" id="ListBoxAccessories" style="height:70px;width:380px;"></select>
</td>
<td width="400px" height="21px" rowspan="2" valign="bottom">
<input id="ButtonAccessoriesAdd" type="button" value="追加" class="button" onclick="ButtonAccessoriesAdd_onclick()" />
<div id="divFileUpload">
</div>
<input type="file" name="FileUpload1" id="FileUpload1" style="display:none;" /></td>
</tr>
<tr>
<td width="140px" height="19px" bgcolor="#FFFFFF" rowspan="2" ></td>
</tr>
<tr>
<td width="400px" height="36px" rowspan="2" valign="middle">
<input id="ButtonAccessoriesDel" type="button" value="削除" class="button" onclick="ButtonAccessoriesDel_onclick()" /></td>
</tr>
<tr>
<td width="140px" height="19px" bgcolor="#FFFFFF" ></td>
</tr>
<tr>
<td class="label_td" style="height: 7px" ><font> 回覧先 </font><font class = "small_font">*</font></td>
<td width="810px" colspan="3" style="height: 7px"> <select name="DropDownListRetro" id="DropDownListRetro" style="width: 249px; height: 19px"></select></td>
</tr>
<tr>
<td width="140px" bgcolor="#FFFFFF" rowspan="2" height="80" > </td>
<td rowspan="2" height="80" valign="top" style="width: 255px">
<select size="4" name="ListBox1" id="ListBox1" style="height:80px;width:260px;"></select>
</td>
<td width="155px" valign="middle" height="40px" >
<p align="center">
<input type="submit" name="ButtonRetroAdd" value="追加 →" id="ButtonRetroAdd" class="button" />
</td>
<td width="400px" rowspan="2" valign="top" height="80px" >
<select size="4" name="ListBox2" id="ListBox2" style="height:80px;width:260px;"></select>
</td>
</tr>
<tr>
<td width="155" valign="top" height="40px">
<p align="center">
<input type="submit" name="ButtonRetroDel" value="← 削除" id="ButtonRetroDel" class="button" />
</td>
</tr>
<tr>
<td width="140" height="20" bgcolor="#FFFFFF" > </td>
<td width="810" height="20" colspan="3" valign="bottom"> <input type="button" value="回覧する" name="B6" class="button" onclick = "document.location='retro_list.htm'" id="Button1" />
<input type="reset" value="クリア" class="button" />
<input id="Submit1" type="submit" value="submit" /></td>
</tr>
</table>
</div>
<div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBQKF4+4fAqTku+oLAoGg6aYEAp/DmZEBAp7Dvf8G1LFonaIZWT2A1wvsrDN/TlnG9YA=" />
</div></form>
</body>
</html>
var flag=false;
function submitOK(){
.......
///确认是否submit
return flag;
}
</script>
<html>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1" enctype="multipart/form-data">
<div>
<script language="javascript" type="text/javascript">
// <!CDATA[
var numFileIndex = 0;function ButtonAccessoriesAdd_onclick()
{
var numlistboxLength;
var strFilePath; // save filepath
var objNewFile = document.createElement("input"); // create a new element <input/>
objNewFile.type = "file"; // edit type="file" <input type="file" />
objNewFile.name = "fileUpload"+ numFileIndex;
objNewFile.id = "fileUpload"+ numFileIndex; // add a id <input type="file" id="fileUpload1" />
numFileIndex = numFileIndex + 1;
document.getElementById("divFileUpload").appendChild(objNewFile); // append the <input type="file"/> to divFileUpload
objNewFile.click();
}
// ]]>
</script>
<table border="0" width="950" cellspacing="3" cellpadding="0">
<tr>
<td class="label_td"><font> 添付資料</font></td>
<td width="400" height="57" rowspan="4" colspan="2" valign="top">
<select size="4" name="ListBoxAccessories" id="ListBoxAccessories" style="WIDTH:380px;HEIGHT:70px">
</select>
</td>
<td width="400" height="21" rowspan="2" valign="bottom">
<input id="ButtonAccessoriesAdd" type="button" value="追加" class="button" onclick="ButtonAccessoriesAdd_onclick()">
<div id="divFileUpload">
</div></td>
</tr>
<tr>
<td width="140" height="20" bgcolor="#ffffff"> </td>
<td width="810" height="20" colspan="3" valign="bottom"><input id="Submit1" type="submit" value="submit"></td>
</tr>
</table>
</div>
</form>
</body>
</html>
document.getElementById(objNewFile.id).click();不就是:
strFilePath = objNewFile.value;
objNewFile.click();先吃饭,吃完饭再来研究
------------------------------------------------------------
不明白为什么会这样,难道是ie的安全措施吗?
郁闷死了
<input id="Submit1" type="submit" value="submit" />改为:<input id="btnSubmit" type="button" value="submit" onclick="javascript:document.Forms[0].submit();" >
----------------------------------------------
改完了这句出错
在其它的框架里调用这个窗口的file.click()是可以的,但在本窗口却不可以,调用的时候虽不出错,但调用完后submit时就出错。
(参见http://www.123du.com的“设置”的“导入设置”---需要先“导出设置”才可以试验。)简化成这样了:
<html><body><form name="form1" method="post" id="form1">
<input type="button" value="qqqq" onclick="document.getElementById('fileUpload').click();">
<input type=file name=fileUpload id=fileUpload onchange="alert('a');this.form.submit();alert('a');">
</form></body></html>
不就完事了