我们常常在邮箱等网页中用到全选,反选,取消选择等操作,其实,这个很简单。下面举个例子来看下:
<script language=javascript>
function selectall()
{
var a = document.getElementsByTagName("input");
for (var i=0; i<a.length; i++)
if (a.type == "checkbox") a.checked = true;
}
function selectnone()
{
var a = document.getElementsByTagName("input");
for (var i=0; i<a.length; i++)
if (a.type == "checkbox") a.checked = false;
}
function select()
{
var a = document.getElementsByTagName("input");
for (var i=0; i<a.length; i++)
if (a.type == "checkbox") a.checked = !a.checked;
}
</script>
接下来,在body中添加3个按钮:
<input name="thes" type="button" value="全选" />
<input name="thes" type="button" value="取消选择" />
<input name="thes" type="button" value="反选" />
[ 本帖最后由 yaokai 于 2008-12-16 13:17 编辑 ] |