<!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>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号