通过document.getElementsByTagName获取表单元素

Original 2019-04-11 15:00:43 327
abstract:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>表单选择器</title></head><body><form action="">姓名:<input type="text

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>表单选择器</title>


</head>

<body>

<form action="">

姓名:<input type="text">

密码:<input type="password">

</form>

<script>

var form=document.getElementsByTagName('form')[0]

console.log(form)

// form.setAttribute('style','background:red');

form.style.background="green"


</script>

</body>

</html>


Correcting teacher:天蓬老师Correction time:2019-04-11 16:04:28
Teacher's summary:选择元素是操作dom的第一步, 也是最重要的一步, 选择一个dom元素, 有很多方法的时候,要选择一种最简单的

Release Notes

Popular Entries