12-06整理

①
//js获取Table并改变它的样式
<script type="text/javascript"> 
function setColSpan() 
{
	var x=document.getElementById('myTable').rows[0].cells //获取table的第一行
	x[0].colSpan="1" 	//改变table的样式
	x[1].colSpan="3" 	//同上
}
</script>
<table id="myTable" border="1"> 
<tr> 
	<td colspan="2">单元格1</td> 
	<td colspan="2">单元格2</td> 
</tr> 
<tr> 
	<td>单元格3</td> 
	<td>单元格4</td> 
	<td>单元格5</td> 
	<td>单元格6</td> 
</tr> 
</table> 
<input type="button" onclick="setColSpan()" value="改变colspan值"> 

②
//js中的定时循环调用函数 setInterval (无限弹)和对应的停止函数
var timer							 	//首先要声明一个变量用来存储setInterval返回

的值.
timer=setInterval("alert('123')",500);	//用声明好的变量存储setInterval返回的值.
clearInterval(timer);					//清除setInterval函数
如果确实要在setInterval方法中调用参数,并且该函数需要传递参数,那么可以通过通过如下方式:把要传的值声明为全局变量,然

后在方法中进行调用.例如:
<script type="text/javaScript">
 var n=1,obj ;
 function f1()
 { obj =setInterval(f2(),1000) }
 function f2()
  { alert(n+=n;)}
</script>


③
//js获得本页网址
var Url = window.location.href;

④
//js控制保存本页面
document.execCommand("SaveAs","","C:\\index.htm"); //1.要进行的操作名,2.默认保存到的地址和文件名和文件类型
function save(dizhi){
	document.execCommand("SaveAs","",dizhi); 
}

⑤
//打开,另存为,属性,打印"等14个JS代码
■打开■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(1,1) type=button value=打开> 
<OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■另存为■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(4,1) type=button value=另存为><OBJECT 

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■属性■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(10,1) type=button value=属性><OBJECT 

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■打印■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(6,1) type=button value=打印><OBJECT 

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■页面设置■ 
<input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置><OBJECT 

classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0></OBJECT> 
■刷新■ 
<input type=button value=刷新 name=refresh onclick="window.location.reload()"> 
■导入收藏■ 
<input type="button" name="Button" value="导入收藏夹" onClick=window.external.ImportExportFavorites(true,);> 
■导出收藏■ 
<input type="button" name="Button3" value="导出收藏夹" onClick=window.external.ImportExportFavorites(false,);> 
■加入收藏■ 
<INPUT name=Button2 onclick="window.external.AddFavorite(location.href, document.title)" type=button value=加入收藏

夹> 
■整理收藏夹■ 
<INPUT name=Submit2 onclick="window.external.ShowBrowserUI(OrganizeFavorites, null)" type=button value=整理收藏夹> 
■查看原文件■ 
<INPUT name=Button onclick=window.location = "view-source:" + window.location.href type=button value=查看源文件> 
■语言设置■ 
<INPUT name=Button onclick="window.external.ShowBrowserUI(LanguageDialog, null)" type=button value=语言设置> 
■前进■ 
<INPUT name=Submit onclick=history.go(1) type=submit value=前进> 
■后退■ 
<INPUT name=Submit2 onclick=history.go(-1) type=submit value=后退>

⑥
//改变CSS样式
一、局部改变样式(区分大小写)
改变className(不用加上style)
document.getElementById('t2').className=”…” 
改变classText(必须加上style)
document.getElementById('t2').style.cssText=”…” 
直接改变控件的CSS的样式
document.getElementById('t2').style.backgroundColor=”#003366″ 
二、全局改变样式(换肤)
给现在使用的CSS样式加一个id,换肤的时候,更改引用的CSS样式的路径,例如:
<link rel = "stylesheet" type="text/css" id="css" href="firefox.css" /> 
<span on click="javascript:document.getElementById('css').href = 'ie.css'">点我改变样式</span> 

⑦
//生成随机数,参数为(最小值,最大值)
function GetRnd(min,max){
 return parseInt(Math.random()*(max-min+1));  
}

⑧
//js中把字符串转化为数字
parseInt("123"); //123
posted @ 2010-12-06 17:39  kelin418  阅读(160)  评论(0编辑  收藏  举报