Summary of HTML tags that are confusing and error-prone

WBOY
Release: 2016-08-08 09:19:54
Original
972 people have browsed it

After struggling for a day, I finally have a clear understanding of the correct use of HTML tags and their respective applicability. Here is a brief summary to avoid making similar mistakes again.

Everything is due to such a problem

<html>
<head>
</head>
<body>
	<form id="form1" method="get" >	
		用户名:<input type="text" id="name" name="name" />
		<p id="username"></p>
		<br />
		密码:<input type="password" id="password" name="password" />
		
		<button type="submit" /button>		
	</form>

	<script>
	window.x=document.getElementById("username");
	window.
	{
		document.getElementById('name').focus();
	}
	//
	function mUp()
	{	
		if(document.getElementById('name').value=="")
		{
			x.innerHTML = "用户名不能为空";
			//alert("不能为空");
		}
		else
			document.getElementById('form1').action="/login";
	}
	</script>	
</body>
</html>
Copy after login

Run the above code and click the "Login" button when nothing is entered. It will prompt "The user name cannot be empty", but it will crash after only appearing once. What is the reason?

The key is that there will be two events triggered by

<button type="submit" /button>	
Copy after login
at this time. First, call the function corresponding to onclick, and then automatically submit (because the type is submit at this time), which will naturally overwrite the prompt. So setting the type to button can solve the problem.

The following is a brief summary,

HTML tag's type attribute

value description
button defines clickable buttons (In most cases, used through JavaScript startup script ).
checkbox Define checkboxes.
file Define input fields and "Browse" button for file upload.
hidden Define hidden input fields.
image Define the submit button in the form of an image.
password Define the password field. Characters in this field are masked.
radio Define radio buttons.
reset Define the reset button. The reset button clears all data in the form.
submit Define the submit button. The submit button will send the form data to the server.
text Define a single-line input field where the user can enter text. The default width is 20 characters.
Note: type=button: It’s just a button function; type=submit: it’s a form to send . The type attribute of the HTML
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template