把js代码放到html标签后面试试,
firefox的加载机制和ie不一样,
firefox的加载机制和ie不一样,
解决方案 »
- 请教一下:asp中“缺少对象”问题
- 【求代码】带复选框的树
- 首页js调用请教
- 解决单页面加载图片过多单个图片过大加载慢的问题
- 请好心的朋友们帮我看看这个程序应怎么写,我的问题是如何能根据点击当前的链接动态算出菜单出现的位置,谢谢大家了。
- 页面里有一段将表格转为excle的脚本。文件保存为htm可以运行,但存成asp提示”服务器不能创建对象“
- 关闭弹出窗口刷新父窗口的怪问题!
- 跪求关于js的资料
- 要打开的页面没有最大最小化按钮怎做?
- 为什么location.href页面不刷新?
- js读取xml
- ---------------------------这5行代码哪里错了??? 显示b为定义??-------------------------------
<head>
<title>Elements </title>
<script type='text/javascript'>
function valid(){
var total = 0;
var friends = document.form1.elements;
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends" && friends[i].checked)
{
total++;
}
} if (total == 0){
document.form1.delete1.disabled = true;
document.form1.update.disabled = true;
}
else if (total == 1){
document.form1.delete1.disabled = false;
document.form1.update.disabled = false;
}
if (total >= 2){
document.form1.delete1.disabled = true;
document.form1.update.disabled = false;
}
}
function selectAll(){
var friends = document.form1.elements;
if (document.form1.all.checked == true)
{
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = true;
}
}
}
else
{
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = false;
}
}
}
}
function selectReversed(){
var friends = document.form1.elements;
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = !friends[i].checked;
}
}
}
</script>
</head> <body onload="valid();">
<form name="form1" method="get" action="">
<input type="button" name="delete1" value="全选">
<input type="checkbox" name="all" onclick="selectAll();valid();" /> |
<input type="button" name="update" value="反选">
<input type="checkbox" name="reversed" onclick="selectReversed();valid();" /> |
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
</form>
</body>
</html>
不要把名字定义为delete 这个是javascript的关键字 改成delete1就可以了
……
害得我看了半天:
<html>
<head>
<title>Elements </title>
<script>
function valid(){
var total = 0;
var friends = document.form1.elements;
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends" && friends[i].checked)
{
total++;
}
}
alert(total);//check total value
if (total == 0){
document.form1.delete1.disabled = true;
document.form1.update.disabled = true;
}
else if (total >= 1){
document.form1.delete1.disabled = false;
document.form1.update.disabled = false;
}}
function selectAll(){
var friends = document.form1.elements;
if (document.form1.all.checked == true)
{
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = true;
}
}
}
else
{
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = false;
}
}
}
}
function selectReversed(){
var friends = document.form1.elements;
for (var i=0; i <friends.length; i++)
{
if (friends[i].name == "friends")
{
friends[i].checked = !friends[i].checked;
}
}
}
</script>
</head><body >
<form name="form1" method="get" action="">
<input type="button" name="delete1" value="全选">
<input type="checkbox" name="all" onclick="selectAll();" /> ¦
<input type="button" name="update" value="反选">
<input type="checkbox" name="reversed" onclick="selectReversed();valid();" /> ¦
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
<input type="checkbox" name="friends" onclick="valid();" />
</form>
</body>
</html>