程式狂想筆記

一個攻城師奮鬥史

0%

[JavaScript]JavaScript原生的找子元素(getElementsByClassName)

最近幫新進同事看code,因為帶他的人是使用JavaScript
原本想說盡量使用動態抓取,後來不知道原生怎麼寫
結果還是使用 $('#table').find(' tr').size()

想說JavaScript應該也是有抓法才對

就上網找了一下資訊
原本以為可以Document.getElementById(‘id’).getElementsByName(‘xxxx’)
結果是我錯了orz

document.getElementById(“intro”);
document.getElementsByName()

Element.getElementsByClassName()
Element.getElementsByTagName()

1
2
<form name='form1_name' id='form1_id'>
</form>

document.form1_name;
document.forms[‘form1_id’]

document

https://www.w3schools.com/js/js_htmldom_elements.asp

參考來源:
JavaScript DOM Elements
https://www.w3schools.com/js/js_htmldom_elements.asp
document.getElementsByClassName
https://www.w3schools.com/js/js_htmldom_elements.asp
Element - Web APIs | MDN
https://developer.mozilla.org/zh-TW/docs/Web/API/Element
What’s the point of HTML forms name attribute? - Stack Overflow
http://stackoverflow.com/questions/8946320/whats-the-point-of-html-forms-name-attribute
Element.name - Web APIs | MDN
https://developer.mozilla.org/en-US/docs/Web/API/Element/name
DOM Version
https://www.w3schools.com/jsref/coll_doc_forms.asp
DOM概述 - Web API 接口 | MDN
https://developer.mozilla.org/zh-CN/docs/Web/API/Document_Object_Model/Introduction
.form1DOM Level
http://blog.xuite.net/abgne/diary1/5896789-%E5%8F%96%E5%BE%97+HTML+%E4%B8%AD%E7%9A%84%E5%85%83%E7%B4%A0
DOM Level 要了解嗎 - Google 搜尋
https://www.google.com.tw/search?q=DOM+Level+%E8%A6%81%E4%BA%86%E8%A7%A3%E5%97%8E&ei=jzcHWcCgIcW10ATyk7-YAw&start=10&sa=N&biw=1600&bih=809
JavaScript浏览器对象——表单(Form)
http://www.monmonkey.com/javascript/liulanqi8.html