一、Javascript遍历整个页面控件示例
function checkall(val)
{
for(var i=0;i<document.all.length;i++)
{
//<input type="text" ......> tagName="INPUT" type="text"
//<input type="checkbox" ......> tagName="INPUT" type="checkbox"
//<select ......> tagName="SELECT" type="select-one"
if(document.all(i).tagName == "SELECT" && document.all(i).type == "select-one" && document.all(i).id != "dropAll")
{
document.all(i).options[val].selected = true;
}
}
}
{
for(var i=0;i<document.all.length;i++)
{
//<input type="text" ......> tagName="INPUT" type="text"
//<input type="checkbox" ......> tagName="INPUT" type="checkbox"
//<select ......> tagName="SELECT" type="select-one"
if(document.all(i).tagName == "SELECT" && document.all(i).type == "select-one" && document.all(i).id != "dropAll")
{
document.all(i).options[val].selected = true;
}
}
}
二、在客户端即时显示所选图片示例
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function showImg(e)
{
var image=new Image();
image.src=e.value;
document.getElementById("s").style.display = "";
document.getElementById("s").src = e.value;
}
</script>
</head>
<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
<img id="s" style="display:none" />
<input type="file" name="file" onchange="showImg(this);" />
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function showImg(e)
{
var image=new Image();
image.src=e.value;
document.getElementById("s").style.display = "";
document.getElementById("s").src = e.value;
}
</script>
</head>
<body>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
<img id="s" style="display:none" />
<input type="file" name="file" onchange="showImg(this);" />
</form>
</body>
</html>
三、window.open()
window.open(sUrl [, sName] [, sFeatures] [, bReplace]);
sURL
| 可选。字符串--指定新的文档的URL地址。如果没有指定这一项,那么将会是一个空的(about:blank)。 | |
sName
| 可选。字符串--新生成窗口的名字。可以用作form或者a中Target的值。 | |
_blank
| sURL被加载到一个新的未命名的窗口。 | |
_media
| sURL被加载到一个媒体栏中。(仅适合IE6以及以后版本浏览器) | |
_parent
| sURL被加载到目前框架的上层框架上。如果没有上层框架,则此项的值与_self的值相同。 | |
_search
| sURL被打开在浏览器的查找窗口。(仅适合IE5以及以后的浏览器) | |
_self
| sURL在当前的窗口上打开,覆盖以前的内容。 | |
_top
| sURL可能会加载到任何框架支架(Frameset)上,如果没有定义Frameset,此项值与_self的值相同。 | |
sFeatures
| 可选。字符串--列出对象表并用逗号分开。每一项都有自己的值,他们将被分开(如:"fullscreen=yes, toolbar=yes")。下面是被支持的各种特性。 | |
channelmode = { yes | no | 1 | 0 } | 是否在窗口中显示阶梯模式。默认为no。 | |
directories = { yes | no | 1 | 0 } | 是否在窗口中显示各种按钮。默认为yes。 | |
fullscreen = { yes | no | 1 | 0 } | 是否用全屏方式显示浏览器。默认为no。使用这一特性时需要非常小心。因为这一属性可能会隐藏浏览器的标题栏和菜单,你必须提供一个按钮或者其他提示来帮助使用者关闭这一浏览窗口。ALT+F4可以关闭窗口。一个全屏窗口必须使用阶梯(channelmode)模式。 | |
height = number | 指定窗口的高度,单位是像素。最小值是100。 | |
left = number | 指定窗口距左边框的距离,单位是像素。值必须大于或者等于0。 | |
location = { yes | no | 1 | 0 } | 指定是否在窗口中显示地址栏。默认为yes。 | |
menubar = { yes | no | 1 | 0 } | 指定是否在窗口中显示菜单栏。默认为yes。 | |
resizable = { yes | no | 1 | 0 } | 指定是否在窗口中显示可供用户调整大小的句柄。默认为yes。 | |
scrollbars = { yes | no | 1 | 0 } | 指定是否在窗口中显示横向或者纵向滚动条。默认为yes。 | |
status = { yes | no | 1 | 0 } | 指定是否在窗口中显示状态栏。默认为yes。 | |
titlebar = { yes | no | 1 | 0 } | 指定是否在窗口中显示标题栏。在非调用HTML Application或者一个对话框的情况下,这一项将被忽略。默认为yes。 | |
toolbar = { yes | no | 1 | 0 } | 指定是否在窗口中显示工具栏,包括如前进、后退、停止等按钮。默认为yes。 | |
top = number | 指定窗口顶部的位置,单位是像素。值必须大于或者等于0。 | |
width = number | 指定窗口的宽度,单位是像素。最小值是100。 | |
bReplace
| 可选。当sURL被加载到同一窗口时,这个布尔型变量指定是否这个sURL新建立一个条目,或者是加到目前该窗口的历史记录上。 | |
true
| sURL覆盖当前文档的历史纪录。 | |
false
| sURL在历史记录中建立一个新的条目。 |