Blogger Information
Blog 11
fans 0
comment 0
visits 21148
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
根据name获取元素
玄夜的博客
Original
1700 people have browsed it
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<!--name属性不是所有元素都有,只有一些特定元素才有,表单,表单内的元素,图像,iframe-->
		<form name="login">
			<input type="text" name="uesername" />
			<input type="password" name="password" />
			<button name="button">提交</button>
		</form>
	</body>
	
	<script>
//		getElementsByName()返回的是一个节点列表数组,NodeList
		var login = document.getElementsByName('login')[0]
		console.log(login)
		login.style.background = 'pink'
		
		//可以把name属性当成document对象的属性使用
		var login1 = document.login;
		console.log(login1)
		login1.style.background = 'yellow'
	</script>
</html>


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post