1、〖打开〗命令的实现
[格式]:document.execCommand("open")
[说明]这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
[举例]在<body></body>之间加入:
<a href="###" onclick=document.execCommand("open")>打开</a>
2、〖使用 记事本 编辑〗命令的实现
[格式]:location.replace("view-source:"+location)
[说明]打开记事本,在记事本中显示该网页的源代码。
[举例]在<body></body>之间加入:
<a href="###" onclick=location.replace("view-source:"+location)>使用 记事本编辑</a>
3、〖另存为〗命令的实现
[格式]:document.execCommand("saveAs")
[说明]将该网页保存到本地盘的其它目录!
[举例]在<body></body>之间加入:
<a href="###" onclick=document.execCommand("saveAs")>另存为</a>
4、〖打印〗命令的实现
[格式]:document.execCommand("print")
[说明]当然,你必须装了打印机!
[举例]在<body></body>之间加入:
<a href="###" onclick=document.execCommand("print")>打印</a>
5、〖关闭〗命令的实 ......
JavaScript函数语法
函数是进行模块化程序设计的基础,编写复杂的Ajax应用程序,必须对函数有更深入的了解。javascript中的函数不同于其他的语言,每个函 数都是作为一个对象被维护和运行的。通过函数对象的性质,可以很方便的将一个函数赋值给一个变量或者将函数作为参数传递。在继续讲述之前,先看一下函数的 使用语法:
1以下为引用的内容:
2function func1(…){…}
3var func2=function(…){…};
4var func3=function func4(…){…};
5var func5=new Function();
这些都是声明函数的正确语法。它们和其他语言中常见的函数或之前介绍的函数定义方式有着很大的区别。那么在JavaScript中为什么能这么写?它所遵循的语法是什么呢?下面将介绍这些内容。
认识函数对象(Function Object)↑Top
可以用function关键字定义一个函数,并为每个函数指定一个函数名,通过函数名来进行调用。在JavaScript解释执行时,函数都是被维护为一个对象,这就是要介绍的函数对象(Function Object)。
函数对象与其他用户所定义的对象有着本质的区别,这一类对象被称之为内部对象,例如日期对象(Dat ......
<script language="javascript">
var timeLen = "0";
var timer = null;
function beginTimer()
{
var hour="0";
var minute="0";
var second="0";
timeLen = parseInt(timeLen)+1;
hour = parseInt(timeLen/3600) ;
minute = parseInt((timeLen-(hour*3600))/60);
second = parseInt((timeLen-(minute*60))%60);
//document.frmtimer.time.innerText = hour+"时"+minute+"分"+second+"秒";
document.getElementById("time").innerText=hour+"时"+minute+"分"+second+"秒";
timer = setTimeout("beginTimer()",1000);
document.getElementById("startButton").disabled = true;
document.getElementById("stopButton").disabled = false;
}
function stopTimer()
{
clearTimeout(timer);
document.getElementById("startButton").disabled = false;
document.getElementById("stopButton").disabled = true;
}
</script>
<html>
<head>
<title>简易计时器</title>
</head& ......
function select_all(){
var paras = document.getElementsByTagName("input");//全选checkbox
if(document.getElementById("all").checked==true){
for(var i=0; i<paras.length; i++){
var name = paras[i].getAttribute("name") //单选checkbox的name均delete_ids
if(name=="delete_ids") paras[i].setAttribute("checked",true);
}
}
else{
for(var i=0; i<paras.length; i++){
var name = paras[i].getAttribute("name")
if(name=="delete_ids") paras[i].setAttribute("checked",false);
}
}
} ......
jQuery片段:
var
// Will speed up references to window, and allows munging its name.
window = this,
// Will speed up references to undefined, and allows munging its name.
undefined,
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$,
jQuery = window.jQuery = window.$ = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
},
// A simple way to check for HTML strings or ID strings
// (both of which we optimize for)
quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
// Is it a simple selector
isSimple = /^.[^:#\[\.,]*$/;
在这一节,我们将讨论同一段jQuery片段的另一个知识点:内置数据类型和内置对象。为了让我们更好地理解代码,我们必须对这一部分内容深入了解。没有牢固的基础,是不可能构筑起坚实的堡垒的。
内置数据类型
内置数据类型,也称作固有数据类型,也就是JS的基本的数 ......
function AddDropDownList(id,fatherCtl)
{
if(!document.getElementById(id))
{
var ddl = document.createElement('select');
ddl.setAttribute("id",id);
if(fatherCtl&&document.getElementById(fatherCtl))
document.getElementById(fatherCtl).appendChild(ddl);
else
document.body.appendChild(ddl);
}
}
//删除指定的下拉框
function RemoveDropDownList(id)
{
var ctl = document.getElementById(id);
if(ctl)
&nbs ......