1. Descrição
(1) Retorne uma referência ou nó ao elemento de acordo com o valor de identificação do elemento fornecido
document.getElementById ("tr_th")(2) Retornar uma referência ou nó a um grupo de elementos de acordo com as marcas no parâmetro
Document.getElementsByTagName ("TD")2. Implementar código -fonte
<! xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> javascript estiliza através de id e nome <//stylesty> <styset) 1px #cccccc sólido; } </style> <script type = "text/javascript">/*** estilos de javascript através de id e nome*/função setFontColor () {// Obtenha o ID do cabeçalho na tabela var tabid = document.getElementById ("tr_th"); // Defina a cor do texto do cabeçalho Tabid.style.color = "amarelo"; // obtenha o td var tabname = document.getElementsByTagName ("td"); // calcule o número de td var len = tabname.length; // transf o td na tabela e defina a cor do conteúdo no td para (var i = 0; i <len; i ++) {tabName [i] .style.color = "blue"; }} </script> </adhead> <body> <tabela CellPadding = "1" CellPacing = "0" style = "borda: 1px #cccccc sólido; largura: 50%; text-align: Center;" <thhhhhhhth = "thhhhhhth =" thhhhhhth = "AGIDO <TH> AGIA <THTHO <THHO AGIDO <THO) <td> 2012010101 </td> <td> zhang sansan </td> <td> 23 </td> <td> masculino </td> </tr> <tr> <td> 2012010102 </td> <tliu sisi </td> <td> </td> type = "Button" value = "Set Color" OnClick = "setFontColor ()"/> </body> </html>3. Alcance os resultados
(1) Inicialização
(2) Clique no botão "Set Color"