<div id = 'DIV' class = 'className'>1</div> <div id = 'DIV'>2</div> <div id = 'DIV'>3</div> <script language="JavaScript"> <!-- document.getElementsById = function(id) { if (typeof(id) == 'string') { var all = document.getElementsByTagName('*'); var length = all.length; var elements = []; while (length) { if (all[--length]['id'] == id) { elements.unshift(all[length]) } } return elements.length == 0 ? null : elements.length == 1 ? elements[0] : elements } return null } alert( document.getElementsById('DIV') ) //--> </script>
如何用getElementById选择多个标签?
最新推荐文章于 2024-09-25 15:23:45 发布