有這么個form表單
<form action=""> <input type="text"> <select> <option value="">1</option> <option value="">2</option> </select> </form>
獲取form標簽里的所有表單元素的dom,
var form = document.querySelector('form') // 這里是querySelector,不是querySelectorAll var ele = form.elements
注意 : 非表單元素不能這么獲取,或者,form標簽里的其他非表單標簽是獲取不了的
例如,下面就不能通過xxx.elements來獲取
<div> <select> <option>選項一<option> </select> </div>
還有,form標簽里的非表單元素,不能通過xxx.elements來獲取
<form> <input type="test"/> <p>p標簽</p> <!--這個p標簽是獲取不了的--> </form>