submit的替代
1、用图片代替提交按钮submit和重置按钮reset,给图片加onclick事件
<script language="javascript"> function fsubmit(obj){ obj.submit(); } function freset(obj){ obj.reset(); } </script> <form id="form1" name="form1" method="post" action="login.asp"> 姓名: <input type="text" name="textfield" /> <img src="uploads/200707/30_145425_001.jpg" onClick="javascript:fsubmit(document.form1);"> <img src="uploads/200707/30_145428_002.jpg" onClick="javascript:freset(document.form1);"> </form>
2、给1的图片加上style,用于弥补方法1鼠标移到图片上无反应,未能给客户好的浏览体验
<script language="javascript"> function fsubmit(obj){ obj.submit(); } function freset(obj){ obj.reset(); } </script> <form id="form1" name="form1" method="post" action="login.asp"> 姓名: <input type="text" name="textfield" /> <img src="uploads/200707/30_145425_001.jpg" style="cursor:hand;" onClick="javascript:fsubmit(document.form1);"> <img src="uploads/200707/30_145428_002.jpg" style="cursor:hand;" onClick="javascript:freset(document.form1);"> </form>
3、用图片代替提交按钮submit和重置按钮reset,并加上链接,效果同2
<script language="javascript"> function fsubmit(obj){ obj.submit(); } function freset(obj){ obj.reset(); } </script> <form id="form1" name="form1" method="post" action="login.asp"> 姓名: <input type="text" name="textfield" /> <a href="javascript:fsubmit(document.form1);"><img src="uploads/200707/30_145425_001.jpg" border="0" /></a> <a href="javascript:freset(document.form1);"><img src="uploads/200707/30_145428_002.jpg" border="0" /></a> </form>
4、使用图像域。由于默认图像域点击时都是提交表单,因而要进行适当的处理:
<script language="javascript"> function fsubmit(obj){ obj.submit(); } function freset(obj){ obj.reset(); } </script> <form id="form1" name="form1" method="post" action="login.asp"> 姓名: <input type="text" name="textfield" /> <input type="image" name="imageField" onClick="javascript:fsubmit(document.form1);return false;" src="uploads/200707/30_145425_001.jpg"> <input type="image" name="imageField2" onClick="javascript:freset(document.form1);return false;" src="uploads/200707/30_145428_002.jpg"> </form>
要注意的是JS中表单提交和重置事件后必须加(),如submit()和reset()
5.button 直接跳转
onclick="javascript:window.location.href='aa.htm'"
onclick="location='URL'"
onclick="window.location.href='?id=11'"