日期:2014-05-16 浏览次数:20452 次
<!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 selText()
{
document.getElementsByTagName('input')[0].select()
}
function setFocus()
{
document.getElementsByTagName('input')[0].focus()
}
function loseFocus()
{
document.getElementsByTagName('input')[0].blur()
}
function check()
{
document.getElementById("myCheck").checked=true;
selText();
}
function uncheck()
{
document.getElementById("myCheck").checked=false
}
function checkAll(name)
{
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++)
{
if((el[i].type=="checkbox") && (el[i].name==name))
{
el[i].checked = true;
}
}
}
function clearAll(name)
{
var el = document.getElementsByTagName('input');
var len = el.length;
for(var i=0; i<len; i++)
{
if((el[i].type=="checkbox") && (el[i].name==name))
{
el[i].checked = false;
}
}
}
</script>
</head>
<body>
<form>
<p><input type="text" name="wenben" value="内容" onfocus="this.select();" /></p>
<p><input type="button" value="选取文本内容" onclick="selText()"></p>
<p><input type="button" onclick="setFocus()" value="设置焦点" /><p>
<p><input type="button" onclick="loseFocus()" value="失去焦点" /><p>
<p><input type="checkbox" id="myCheck" /></p>
<p><input type="button" onclick="check()" value="选定复选框" /></p>
<p><input type="button" onclick="uncheck()" value="取消选定复选框" /></p>
<input type="checkbox" name="test" value="" onclick="if(this.checked==true) { checkAll('test'); } else { clearAll('test'); }">字母全选开关
<input type="checkbox" name="test" value="a">a
<input type="checkbox" name="test" value="b">b
<input type="checkbox" name="test" value="c">c