这是为什么呢? onclick="j.click()"这是什么?说明你点第一次时onclick函数没有解析!先考虑函数放置的位置!再验查语法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 重点问题是你的check函数是什么,需要贴出来 <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">你可以把type改成button的,然后把submit放到check()函数里,试试看<input name="提交" type="button" class="bu" value="导 入" onClick="check()"> check() 函数就是一个简单的判断输入是否为空function check(){ if(document.form1.filepath.value == null ||document.form1.filepath.value =="") { alert("文件路径不能为空!") return false; } return true;}但是如果文件路劲为空的时候只点击一次就可以出现alert提示框了 <input name="提交" type="submit" class="bu" value="导 入" onClick="return check()"> 把提交触发的事件写在表单里看看<from onSubmit="return check();"> <input name="提交" type="submit" class="bu" value="导 入" onClick="return check()"> <input name="提交" type="submit" class="bu" value="导 入" onClick="check()" causesvalidation=false> function check(){ if(document.form1.filepath.value == null ||document.form1.filepath.value =="") { alert("文件路径不能为空!") return false; } return true; } <input name="提交" type="submit" class="bu" value="导 入" onClick="return check();" causesvalidation=false> function check(){ if(document.form1.filepath.value == null ||document.form1.filepath.value =="") { alert("文件路径不能为空!") return false; } return true;}<body style="background-color: #D6EAF2"><form name="form1" method="post" action="excelImport.do"> <table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2"> <tr> <td width="25%" height="25"> </td> <td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td> <td width="26%"> </td> </tr> <tr > <td colspan="3"><div align="center"> <input type=file name=j style="display: none;" onchange="filepath.value=value"> <input name="filepath" width="300px" height="10px"> <input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览"> <input name="提交" type="submit" class="bu" value="导 入" onClick="check()"> </div></td> </tr><tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr> </table> </form></body>这就是全部的代码,按照楼上的方法修改,还是没用 <form name="form1" method="post" action="excelImport.do" onsubmit="return check();"><input name="提交" type="submit" class="bu" value="导 入"> 可能大家把我的意思理解错误了,我的意思是:在没有往file里面填入路径的时候,点击“导入”按钮只需要点一次就能提示alert对话框“文件路径不能为空!”但是如果往file里面填入了路径呢,点击“导入”按钮却要点两下才能提交整个表单请问这是为什么,整个代码我都贴上来了,请大家帮帮呀 action="excelImport.do" 你这个里面是什么东西!是否有异常发生? 这个是struts里的action机制没有错误我刚才测试了下把其中的一段代码删除掉就不会出现我所说的情况了。<input type=file name=j > <input name="提交" type="submit" class="bu" value="导 入" onClick="check()">我把文件域隐藏的浏览按钮再都显示出来,就不会出现这样的情况了 你的做法貌似是将file控件的文件路径值放到了hidden中,然后在上传提交。hidden恐怕没这权限吧~~我这里提示是拒绝访问! function check(){ if(document.form1.filepath.value == null ||document.form1.filepath.value =="") { alert("文件路径不能为空!") return false; } return true; //document.getElementByID("aa").submit;}<body style="background-color: #D6EAF2"><form name="form1" id="aa" method="post" action="excelImport.do"> <table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2"> <tr> <td width="25%" height="25"> </td> <td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td> <td width="26%"> </td> </tr> <tr > <td colspan="3"><div align="center"> <input type=file name=j style="display: none;" onchange="filepath.value=value"> <input name="filepath" width="300px" height="10px"> <input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览"> <input name="提交" type="submit" class="bu" value="导 入" onClick="check()"> </div></td> </tr><tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"></font></div></td></tr> </table> </form></body>把这段代码去掉试试,<%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%>、或者type="submit"改为type="button" check()函数加上document.getElementByID("aa").submit;试试 点击一次可以提交<script type="text/javascript" > function check(){ if(document.form1.filepath.value == null ||document.form1.filepath.value =="") { alert("文件路径不能为空!") return false; } document.Form1.submit(); return true;} </script></head><body style="background-color: #D6EAF2"><form name="form1" id="Form1" method="post" action="excelImport.do"> <table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2"> <tr> <td width="25%" height="25"> </td> <td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td> <td width="26%"> </td> </tr> <tr > <td colspan="3"><div align="center"> <input type=file name=j style="display: none;" onchange="filepath.value=value"> <input name="filepath" width="300px" height="10px"> <input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览"> <input name="提交" type="button" class="bu" value="导 入" onClick="check()"> </div></td> </tr><tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr> </table> </form></body> <input name="提交" type="button" class="bu" value="导 入" onClick="check()">document.Form1.submit(); action="excelImport.do"把这个贴出来excelImport.do时什么东西? 会不会是onchange="filepath.value=value">影响了导入按钮的提交 就是onchange="filepath.value=value">这段代码影响提交。但是又要靠这段代码来获取上传的路径。楼主可能需要换一种方案! 这个js的td属性是如何设定的 script 中写的php代码为什么报错??? javascript怎么在新打开的页面获取旧的页面的值?急 BOSS们帮帮我吧都一星期了! 用JS获取未选择的问题,然后改变颜色,求高手指点 一个简单的问题 利用鼠标点击事件控制表格行的背景问题? 求救,关于IE的javascript的问题? 能不能控制input文本框,不自动显示历史记录。 有个框架页,左边是菜单,右边是内容,如何点击菜单变化右边内容时将框架页的<Title>也变化 辞职了....照例散分... 隔行换色+选中高亮 的高性能解决方案 求助
你可以把type改成button的,然后把submit放到check()函数里,试试看
<input name="提交" type="button" class="bu" value="导 入" onClick="check()">
if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
{
alert("文件路径不能为空!")
return false;
}
return true;
}但是如果文件路劲为空的时候只点击一次就可以出现alert提示框了
<from onSubmit="return check();">
<input name="提交" type="submit" class="bu" value="导 入" onClick="check()" causesvalidation=false>
if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
{
alert("文件路径不能为空!")
return false;
}
return true;
}
<input name="提交" type="submit" class="bu" value="导 入" onClick="return check();" causesvalidation=false>
function check(){
if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
{
alert("文件路径不能为空!")
return false;
}
return true;
}
<body style="background-color: #D6EAF2">
<form name="form1" method="post" action="excelImport.do">
<table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
<tr>
<td width="25%" height="25"> </td>
<td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td>
<td width="26%"> </td>
</tr>
<tr >
<td colspan="3"><div align="center">
<input type=file name=j style="display: none;" onchange="filepath.value=value">
<input name="filepath" width="300px" height="10px">
<input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览">
<input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
</div></td>
</tr>
<tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr>
</table>
</form>
</body>这就是全部的代码,按照楼上的方法修改,还是没用
<input name="提交" type="submit" class="bu" value="导 入">
可能大家把我的意思理解错误了,我的意思是:
在没有往file里面填入路径的时候,点击“导入”按钮只需要点一次就能提示alert对话框“文件路径不能为空!”
但是如果往file里面填入了路径呢,点击“导入”按钮却要点两下才能提交整个表单
请问这是为什么,整个代码我都贴上来了,请大家帮帮呀
没有错误
我刚才测试了下把其中的一段代码删除掉就不会出现我所说的情况了。
<input type=file name=j >
<input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
我把文件域隐藏的浏览按钮再都显示出来,就不会出现这样的情况了
{
if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
{
alert("文件路径不能为空!")
return false;
}
return true;
//document.getElementByID("aa").submit;
}<body style="background-color: #D6EAF2">
<form name="form1" id="aa" method="post" action="excelImport.do">
<table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
<tr>
<td width="25%" height="25"> </td>
<td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td>
<td width="26%"> </td>
</tr>
<tr >
<td colspan="3"><div align="center">
<input type=file name=j style="display: none;" onchange="filepath.value=value">
<input name="filepath" width="300px" height="10px">
<input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览">
<input name="提交" type="submit" class="bu" value="导 入" onClick="check()">
</div></td>
</tr>
<tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"></font></div></td></tr>
</table>
</form>
</body>把这段代码去掉试试,<%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%>、或者type="submit"改为type="button" check()函数加上document.getElementByID("aa").submit;试试
点击一次可以提交
<script type="text/javascript" >
function check()
{
if(document.form1.filepath.value == null ||document.form1.filepath.value =="")
{
alert("文件路径不能为空!")
return false;
}
document.Form1.submit();
return true;
}
</script>
</head>
<body style="background-color: #D6EAF2">
<form name="form1" id="Form1" method="post" action="excelImport.do">
<table width="100%" height="47" border="0" cellpadding="0" cellspacing="0" bgcolor="#D6EAF2">
<tr>
<td width="25%" height="25"> </td>
<td><div align="center" class="style1">您可以先下载<a href="实施">导入模板</a>,然后按照模板格式导入</div></td>
<td width="26%"> </td>
</tr>
<tr >
<td colspan="3"><div align="center">
<input type=file name=j style="display: none;" onchange="filepath.value=value">
<input name="filepath" width="300px" height="10px">
<input name="按钮" type="button" class="bu" onclick="j.click()" value="浏 览">
<input name="提交" type="button" class="bu" value="导 入" onClick="check()">
</div></td>
</tr>
<tr><td colspan="3" height="25"><div align="center" ><font color = "#FF0000"><%=request.getAttribute("msg")==null?"":request.getAttribute("msg")%></font></div></td></tr>
</table>
</form>
</body>
把这个贴出来
excelImport.do时什么东西?
就是onchange="filepath.value=value">这段代码影响提交。但是又要靠这段代码来获取上传的路径。
楼主可能需要换一种方案!