Difference between button element and input element

1. The button element

       1. The type attribute is button, reset, submit.

       2. The default value of the button element in the browser is different, and the button type must be clearly specified (button in IE, submit in other browsers)

       3. When the button element is used in the form, different browsers submit different values ​​(IE submits the value between button elements, other browsers submit the value attribute of the button element)

      4. Inside the button element, you can place content, such as text or images.

Second, the input element

       1. When the type is button, submit, or reset, the value submitted in the form is the value attribute of the input element.

       2. When submitting the form, try to use the input element as much as possible.

3. Use

 When the type is submit, the data of the form is submitted to the server at this time. If the data in the form is changed at this time, the data is immutable.

When the type is button, at this time, it is just a button.

When writing a form, check each item before submitting

Example:

<form>
	
    <button type="submit">click</button>

	<p>webti</p>
</form>
<script type="text/javascript">
		var btn=document.getElementsByTagName('button')[0];
		var p=document.getElementsByTagName('p')[0];
		// alert(btn.type);
		btn.onclick=function (event) {

			alert(event.type);
			p.innerHTML="CCC";
			
		};
</script>


Result: When clicked, the content of p at this time changes, and then the original value is restored.

Don't quite understand this? ?

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325812513&siteId=291194637