js reset类型按钮和button类型按钮有什么不同?

JavaScript026

js reset类型按钮和button类型按钮有什么不同?,第1张

type='reset' 重置按钮,默认点击后触发的是reset事件,会重置其所属form表单里的所有控件,到默认状态(清空已经填写的所有文字内容,将checkbox,radiobox,select等控件重置为默认状态)

type='submit' 提交按钮,默认点击后触发的是表单的submit事件,提交其所属的表单

type='button' 一般按钮,默认点击后触发的是click事件,具体点击后进行什么样的操作,需要自己通过js代码来实现

思路:本题要想实现用javascript做出重置效果需要用到JavaScript实现重置表单(reset)的方法。

例子:

<form id="form1">

<input type="text" id="name"/>

<input type="button" value="这个用JavaScript清除" onclick="document.getElementById('form1').reset()"/>

<input type="reset" value="这个是Form清除" />//reset()重置

</form>

<html>

<head>

 <title></title>

 <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

 <script type="text/javascript">

$(document).ready(function(){

$("#change").click(function(){

$("*").css({"margin":"0","padding":"0"})

})

})

 </script>

</head>

<body>

 <div style="width:500px margin-left:20px padding:50px height:300px background-color:red"></div>

 <div style="width:500px margin-left:50px padding:40px height:300px background-color:blue"></div>

 <input type="button" value="change" id="change">

</body>

</html>