submit功能由图片来实现

1、用图片代替提交按钮submit和重置按钮reset,给图片加onclick事件

<scriptlanguage="javascript">

functionfsubmit(obj){

obj.submit();

}

functionfreset(obj){

obj.reset();

}

</script>

<formid="form1"name="form1"method="post"action="login.asp">

姓名:<inputtype="text"name="textfield"/>

<imgsrc="uploads/200707/30_145425_001.jpg"onClick="javascript:fsubmit(document.form1);">

<imgsrc="uploads/200707/30_145428_002.jpg"onClick="javascript:freset(document.form1);">

</form>

2、给1的图片加上style,用于弥补方法1鼠标移到图片上无反应,未能给客户好的浏览体验

<scriptlanguage="javascript">

functionfsubmit(obj){

obj.submit();

}

functionfreset(obj){

obj.reset();

}

</script>

<formid="form1"name="form1"method="post"action="login.asp">

姓名:<inputtype="text"name="textfield"/>

<imgsrc="uploads/200707/30_145425_001.jpg"style="cursor:hand;"onClick="javascript:fsubmit(document.form1);">

<imgsrc="uploads/200707/30_145428_002.jpg"style="cursor:hand;"onClick="javascript:freset(document.form1);">

</form>

3、用图片代替提交按钮submit和重置按钮reset,并加上链接,效果同2

<scriptlanguage="javascript">

functionfsubmit(obj){

obj.submit();

}

functionfreset(obj){

obj.reset();

}

</script>

<formid="form1"name="form1"method="post"action="login.asp">

姓名:<inputtype="text"name="textfield"/>

<ahref="javascript:fsubmit(document.form1);"><imgsrc="uploads/200707/30_145425_001.jpg"border="0"/></a>

<ahref="javascript:freset(document.form1);"><imgsrc="uploads/200707/30_145428_002.jpg"border="0"/></a>

</form>

4、使用图像域。由于默认图像域点击时都是提交表单,因而要进行适当的处理:

<scriptlanguage="javascript">

functionfsubmit(obj){

obj.submit();

}

functionfreset(obj){

obj.reset();

}

</script>

<formid="form1"name="form1"method="post"action="login.asp">

姓名:<inputtype="text"name="textfield"/>

<inputtype="image"name="imageField"onClick="javascript:fsubmit(document.form1);returnfalse;"src="uploads/200707/30_145425_001.jpg">

<inputtype="image"name="imageField2"onClick="javascript:freset(document.form1);returnfalse;"src="uploads/200707/30_145428_002.jpg">

</form>

要注意的是JS中表单提交和重置事件后必须加(),如submit()和reset()

相关推荐