按钮怎么交替变灰(不可用)啊!!!

wycdavid2008 2008-10-09 06:38:24
html中有一组按钮,怎么样点击其中一个按钮后就变灰(也就是不能点2次!),当点了其他按钮后这个按钮又可以点了!!,请教下该怎么实现???最好用javascript脚本!谢谢啊
...全文
148 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
wycdavid2008 2008-10-10
  • 打赏
  • 举报
回复
谢谢大家的帮忙,尤其要谢谢chinmo ,呵呵
spy2142 2008-10-10
  • 打赏
  • 举报
回复
其实一个全局变量就解决问题了,哪里需要循环啊
<html>
<head>
<script type="text/javascript">
var num=0;
function cl(e,id){
e.disabled="disabled";
if(num){
document.getElementById(num).disabled="";
}
num=id;
}
</script>
</head>

<body>
This is my HTML page. <br>
<input type="button" value="button1" id="b1" onclick="cl(this,'b1')"/>
<input type="button" value="button2" id="b2" onclick="cl(this,'b2')"/>
<input type="button" value="button3" id="b3" onclick="cl(this,'b3')"/>
<input type="button" value="button4" id="b4" onclick="cl(this,'b4')"/>
<input type="button" value="button5" id="b5" onclick="cl(this,'b5')"/>
<input type="button" value="button6" id="b6" onclick="cl(this,'b6')"/>
<input type="button" value="button7" id="b7" onclick="cl(this,'b7')"/>
</body>
</html>
wtcsy 2008-10-09
  • 打赏
  • 举报
回复
恩 没仔细看需求
<input value="111111" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" /><input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />

<script>
function change(e){
if(document.getElementById("ss")!=null)
{document.getElementById("ss").disabled=""
document.getElementById("ss").id=""}
e.disabled="disabled";
e.id="ss"}
</script>
rainxiang 2008-10-09
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 chinmo 的回复:]
引用 11 楼 rainxiang 的回复:

script>
var tmpObj;
function test(obj){
obj.disabled = true;
if(tmpObj)tmpObj.disabled = false;
tmpObj = obj;
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">
<input type="button" id="button3" value="ok3" onclick="test(this);">


呵呵,与我的写的差不多
[/Quote]

恩。。回头看了下。思路一样,不循环就设置个变量来存上次的对象。^_^
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 rainxiang 的回复:]
script>
var tmpObj;
function test(obj){
obj.disabled = true;
if(tmpObj)tmpObj.disabled = false;
tmpObj = obj;
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">
<input type="button" id="button3" value="ok3" onclick="test(this);"> [/Quote]

呵呵,与我的写的差不多
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 wtcsy 的回复:]
HTML code<input value="111111" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" /><input value="222222" type="button" onclick="change(this)" />
<input valu…
[/Quote]
你的还是有问题

oo=false了你再按按钮的时候根本无法执行
if(oo==true)
{e.disabled="disabled";
oo=false
e.id="ss"
}
这部分
rainxiang 2008-10-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 chinmo 的回复:]
引用 6 楼 rainxiang 的回复:

<script>
function test(obj){
for( var i=1;i <=2;i++ ){
document.getElementById("button"+i).disabled=false;
if( obj == document.getElementById("button"+i) )
obj.disabled = true;
}
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">

给你点建议,如果比较多的按钮…
[/Quote]


<script>
var tmpObj;
function test(obj){
obj.disabled = true;
if(tmpObj)tmpObj.disabled = false;
tmpObj = obj;
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">
<input type="button" id="button3" value="ok3" onclick="test(this);">
wtcsy 2008-10-09
  • 打赏
  • 举报
回复
<input  value="111111"  type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" /><input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />

<script>
var oo=true
function change(e){
if(oo==true)
{e.disabled="disabled";
oo=false
e.id="ss"
}
else
{
document.getElementById("ss").disabled=""
document.getElementById("ss").id=""
oo=true
}
}
</script>

随手写的 bug多多 呵呵!!
  • 打赏
  • 举报
回复
<input id="a1"  value="111111"  type="button" onclick="change(this.id)" /> 
<input id="a2" value="222222" type="button" onclick="change(this.id)" />


<script>
var objid;
function change(e){
document.getElementById(e).disabled="disabled" ;
if(objid){
document.getElementById(objid).disabled="" ;}
objid=e;
}
</script>

这个应该比较全面了
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wtcsy 的回复:]
看错要求了

HTML code<input value="111111" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />

<script>
var oo=true
function change(e){
if(oo==true)
{e.disabled="disabled";
oo=false
e.id="ss"
}
else
{
document.getElementById("ss").disabled=""
oo=true
}
}
</script>
[/Quote]

你这个你自己测试一下,如果三个按钮呢??
那么就会出现一样的ID
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 rainxiang 的回复:]
<script>
function test(obj){
for( var i=1;i <=2;i++ ){
document.getElementById("button"+i).disabled=false;
if( obj == document.getElementById("button"+i) )
obj.disabled = true;
}
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">
[/Quote]
给你点建议,如果比较多的按钮怎么办?
难道你也都用FOR循环??都要遍历一遍?
rainxiang 2008-10-09
  • 打赏
  • 举报
回复
<script>
function test(obj){
for( var i=1;i<=2;i++ ){
document.getElementById("button"+i).disabled=false;
if( obj == document.getElementById("button"+i) )
obj.disabled = true;
}
}
</script>
<input type="button" id="button1" value="ok1" onclick="test(this);">
<input type="button" id="button2" value="ok2" onclick="test(this);">
  • 打赏
  • 举报
回复
<input id="a1"  value="111111"  type="button" onclick="change(this.id)" /> 
<input id="a2" value="222222" type="button" onclick="change(this.id)" />

<script>
var objid;
function change(e){
document.getElementById(e).disabled="disabled" ;
objid=e;
document.getElementById(objid).disabled="" ;
}
</script>
  • 打赏
  • 举报
回复
<input id="a1"  value="111111"  type="button" onclick="change(this.id)" /> 
<input id="a2" value="222222" type="button" onclick="change(this.id)" />

<script>
var objid;
function change(e){
e.disabled="disabled" ;
objid=e;
objid.disabled="" ;
}
</script>
wtcsy 2008-10-09
  • 打赏
  • 举报
回复
看错要求了
<input  value="111111"  type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change(this)" />

<script>
var oo=true
function change(e){
if(oo==true)
{e.disabled="disabled";
oo=false
e.id="ss"
}
else
{
document.getElementById("ss").disabled=""
oo=true
}
}
</script>
wtcsy 2008-10-09
  • 打赏
  • 举报
回复
<input value="111111" type="button" onclick="change(this)" />
<input value="222222" type="button" onclick="change1()" />

<script>
function change(e){
e.disabled="disabled"
}
function change1(){
document.getElementsByTagName("input")[0].disabled=""
}
</script>
街头小贩 2008-10-09
  • 打赏
  • 举报
回复
<input type="button" onclick="this.disabled=true;thisformsubmit();" />

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧