childNodes Returns a node list containing the children of a node (if any).
item Accesses individual nodes within the list through an index. Index values are zero-based, so
item(0) returns the first child node.
text Returns the text content of the node.
The following code shows an HTML page containing an XML data island. The data island is contained within
the <XML> element.
<HTML>
<HEAD>
<TITLE>HTML with XML Data Island</TITLE>
</HEAD>
<BODY>
<P>Within this document is an XML data island.</P>
<XML ID="resortXML">
<resorts>
<resort code='1'>Adventure Works</resort>
<resort>Alpine Ski House</resort>
</resorts>
</XML>
</BODY>
</HTML>
For an example, you can cut and paste this sample line of code:
resortXML.XMLDocument.documentElement.childNodes.item(1).text//读取页面上的XML数据岛中的数据
resortXML.documentElement.childNodes.item(0).getAttribute("code")//读取页面上的XML数据岛中的数据
resortXML.documentElement.childNodes[0].getAttribute("code")//读取页面上的XML数据岛中的数据
199.模式窗口
父窗口
var url="aaa.jsp";
var
data=showModalDialog(url,null,"dialogHeight:400px;dialogHeight:600px;center:yes;help:No;status:no;resizab
le:Yes;edge:sunken");
if(data)
alert(data.value);
子窗口
var data=new Object();
data.value1="china";
window.returnValue=data;
window.close();
200.动态设置事件,带参数
<INPUT TYPE="text" NAME="a1">
<SCRIPT LANGUAGE="JavaScript">
<!--
function hah(para)
{
alert(para)
}
a1.onclick=function()
{
hah('canshu ')
}
//a1.attachEvent("onclick",function(){hah('参数')});
//-->
</SCRIPT>//
201.将url转化为16进制形式
var ret = '';
for(var i=0; i < str.length; i++)
{
var ch = str.charAt(i);
var code = str.charCodeAt(i);
if(code < 128 && ch != '[' && ch != '\'' && ch != '=')
{
ret += ch;
}
else
{
ret += "[" + code.toString(16) + "]";
}
}
return ret;//
202.打开新的窗口并将新打开的窗口设置为活动窗口
var newWin=window.open("xxxx");
newWin.focus();//
203.容错脚本
JS中遇到脚本错误时不做任何操作:window.onerror = doNothing;
指定错误句柄的语法为:window.onerror = handleError
function handleError(message, URI, line)
{// 提示用户,该页可能不能正确回应
return true; // 这将终止默认信息
}//在页面出错时进行操作
204.JS中的窗口重定向:
window.navigate("http://www.upschool.com.cn");//
205.防止链接文字折行
document.body.noWrap=true;//
206.判断字符是否匹配.
string.match(regExpression)//
207.
href="javascript:document.Form.Name.value='test';void(0);"//不能用onClick="javacript:document.Form.Name.v
alue='test';return false;"
当使用inline方式添加事件处理脚本事,有一个被包装成匿名函数的过程,也就是说
onClick="javacript:document.Form.Name.value='test';return false;"被包装成了:
functoin anonymous()
{
document.Form.Name.value='test';return false;
}
做为A的成员函数onclick。
而href="javascript:document.Form.Name.value='test';void(0);"相当于执行全局语句,这时如果使用return语句会
报告在函数外使用return语句的错误。
208.进行页面放大
<P onmouseover="this.style.zoom='200%'" onmouseout="this.style.zoom='normal'">
sdsdsdsdsdsdsdsds
</p>//
209.放置在页面的最右边
<input type="text" value='bu2' style="float:right">//
210.通过style来控制隔行显示不同颜色
<style>
tr{}{
bgcolor:expression(this.bgColor=((this.rowIndex)%2==0 )? 'white' : 'yellow');
}
</style>
<table id="oTable" width="100" border="1" style="border-collapse:collapse;">
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
</table>//
211.全屏最大化
newwindow=window.open("","","scrollbars")
if (document.all)
{
newwindow.moveTo(0,0)
newwindow.resizeTo(screen.width,screen.height)
}//
212.根据名字解析xml中的节点值
var XMLDoc=new ActiveXObject("MSXML");
XMLDoc.url="d:/abc.xml";
aRoot=XMLDoc.root;
a1.innerText=aRoot.children.item("name").text;//
213.在页面上解析xml的值
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/5996c682-3472-4b03-9fb0-1e08
fcccdf35.asp
来源:www.upschool.com.cn
作者:未知
关键字:JS,javascript,教程,正则,特效
发表日期:2007-2-10 12:53:00
网页显示有限 阅读全文请下载本文完整版WORD文档
上一篇:预载Gif的2个JS代码(非常有用) 下一篇:
共17页
9 7 [
1] [
2] [
3] [
4] [
5] [
6] [
7] [
8] [
9] [
10] [
11] [
12] [
13] [
14] [
15] [
16] [
17]
8 :>
2008-11-22 5:10:47