- 我的JSP頁面代碼,JS有點問題。但是不知道怎樣解決。只想圖片按鈕可以提交表單
-
<%@ page contentType="text/html; charset=gbk" %>
登陸頁面
<br>
function check(){<br>
var uname = document.all.uname.value;<br>
var upwd = document.all.upwd.value;<br>
if(uname.trim()==""){<br>
alert("用戶名為空,請重新輸入!!!");<br>
return;<br>
}<br>
if(upwd.trim()==""){<br>
alert("密碼為空,請重新輸入!!!");<br>
return;<br>
}<br>
document.all.mf.submit();<br>
}<br>
用戶名:
密 碼:
style="cursor:hand"
onmouseover="document.all.lg.src='img/ddla.gif'"
onmouseout="document.all.lg.src='https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017010615051529.gif'"
onmouseup="document.all.lg.src='img/ddla.gif'"
onmousedown="document.all.lg.src='img/ddlb.gif'"/>
style="cursor:hand"
onmouseover="document.all.cz.src='img/cza.gif'"
onmouseout="document.all.cz.src='https://www.aspphp.online/bianchen/UploadFiles_4619/201701/2017010615051545.gif'"
onmouseup="document.all.cz.src='img/cza.gif'"
onmousedown="document.all.cz.src='img/czb.gif'"/>
最佳回答:
代碼太亂,發個demo給你,少用document.all,only ie支持
<script type="text/javascript">
function check(){
var f=document.form1;
if(f.uname.value==''){alert('用戶名為空,請重新輸入!!!');f.uname.focus();return false;}
if(f.upwd.value==''){alert('密碼為空,請重新輸入!!!');f.upwd.focus();return false;}
f.submit()
}
</script>
<form name="form1">
用戶名:<input type="text" name="uname"/><br/>
密 碼:<input type="password" name="upwd"/>
<img src="1.jpg" onclick="check()"/>
</form>