JavaScript中DOM树的Node接口的一些简单应用
1. 用类名查找元素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">
<html xmlns="http://www.w3.org/1999/xhtml
" >
<head>
<title>Untitled Page</title>
<script type="text/javascript
">
//本页方法:用类名选择元素
function
getElements(cla) {
var
elements = document
.getElementsByTagName("*
");
var
elems = [];
for
(var
i = 0; i < elements.length
; i++) {
if
(elements[i].className && has(elements[i].className,cla)) {
elems.push(elements[i]);
}
}
return
elems;
}
function
has(ele, name
) {
var
clla = [];
if
(ele) clla = ele.split(' ');
for
(var
i = 0; i < clla.length
; i++)
if
(clla[i] == name
) {return
true
};
return
false
;
}
</script>
<style type="text/css
">
.h
{background-color:Aqua;
}
</style>
</head>
<body>
<i id="iiii
" class
="h
">Just test.</i><br />
<span id="ssss
" class
="h
">hehe</span>
<script type="text/javascript
">
var
e = getElements("h
");
var
nn = ""
for
(var
i = 0; i < e.length
; i++) {
nn +="id:
" + e[i].id + "\n
";
nn += "------line------\n
";
}
alert
(nn);
</script>
</body>
</html>
<
script
>
// This function takes a Node n, replaces it in the tree with an Element node
// that represents an HTML <
b
>
tag, and then makes the original node the
// child of the new <
b
>
相关文档:
<script language="javascript">
function closeOpen(Panel) {
var test = document.getElementById('Panel');
if (test.style.display == "none") {
&nb ......
javascript中event.keycode
keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
keycode 32 = space space ......
1. 定义一个用于输出JavaScript代码 的Servlet类。
package com.mycompany.response.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServle ......
用javascript显示XML
你可以用JavaScript显示XML。可以用JavaScript (或 VBScript)从一个XML文件中输入数据并在一个HTML页面内显示XML数据。 要看看XML和HTML是如何相互补充的,可以这样做:首先找到XML 文档(note.xml),然后打开HTML文档
(note.htm),这个HTML文档中包含了阅读X ......
有时候找到别人写的js代码是压缩过的,通过这个工具可以对代码进行格式化。
<html>
<head>
<title>JS格式化工具 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<mce:style><!--
* { padding:0px; margin:5px; font-size:13px; font-fami ......