JavaScript复选框特效 表单内有五个复选框,当第一次单击选中复选框时其后面出现数字1,第二次单击选中出现数字2,以此类推;当第一次的为不选中情况时数字1 不显示,第二次单击选中的出现1,以此类推。求JavaScript怎样实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 类似的,自己改改吧:<input type="checkbox" id="1" onclick="fun(this)"><span id="span1"></span><input type="checkbox" id="2" onclick="fun(this)"><span id="span2"></span><input type="checkbox" id="3" onclick="fun(this)"><span id="span3"></span><input type="checkbox" id="4" onclick="fun(this)"><span id="span4"></span><input type="checkbox" id="5" onclick="fun(this)"><span id="span5"></span><script language="javascript">function fun(box){ if(box.checked){ document.getElementById("span" + box.id).innerHTML = box.id; }else{ document.getElementById("span" + box.id).innerHTML = ""; }}</script> <input type="checkbox" id="1" onclick="fun(this)"><span id="span1" style="display:none;">1</span><input type="checkbox" id="2" onclick="fun(this)"><span id="span2" style="display:none;">2</span><input type="checkbox" id="3" onclick="fun(this)"><span id="span3" style="display:none;">3</span><input type="checkbox" id="4" onclick="fun(this)"><span id="span4" style="display:none;">4</span><input type="checkbox" id="5" onclick="fun(this)"><span id="span5" style="display:none;">5</span><script language="javascript">function fun(box){if(box.checked){document.getElementById("span" + box.id).style.display = "block";}else{document.getElementById("span" + box.id).style.display = "none";}}稍改改,实现的方法很多。看你怎么做了 <input type="checkbox" value="1" onclick="fun(this)"><span id="span1"></span><BR><input type="checkbox" value="2" onclick="fun(this)"><span id="span2"></span><BR><input type="checkbox" value="3" onclick="fun(this)"><span id="span3"></span><BR><input type="checkbox" value="4" onclick="fun(this)"><span id="span4"></span><BR><input type="checkbox" value="5" onclick="fun(this)"><span id="span5"></span><script language="javascript">function fun(box){ var sp = document.getElementById("span" + box.value); if(box.checked){ if (sp.innerHTML == "") sp.innerHTML = 1; else sp.innerHTML = parseInt(sp.innerHTML,10) +1; sp.style.display = ""; } else sp.style.display = "none";}</script> 提示“。。。为空或不是对象” 请问提示我没有分可加了是怎么回事? Qplayer.hta雏形共享--只有几十k,有lrc同步显示,下载;添加本地文件夹,网络歌曲,编辑lrc等功能,html+js,开源方便修改.呵呵 这个javascript的正则这样判断对吗? 求一个不刷新页面,即时在页面上提示信息的思路或方法 文件的创建日期 如何利用鼠标左键点击事件取得表格中被点击单元格的背景颜色? 问题又来了? 这儿真是没有人会吗??如果真没有人解决这个问题,这个论坛,倒闭算了吧。我都发了半个月了。 请问怎么获取Window里面的值? 菜鸟来请假,自动刷新指定框架问题。 Ext 打印
<input type="checkbox" id="1" onclick="fun(this)"><span id="span1"></span>
<input type="checkbox" id="2" onclick="fun(this)"><span id="span2"></span>
<input type="checkbox" id="3" onclick="fun(this)"><span id="span3"></span>
<input type="checkbox" id="4" onclick="fun(this)"><span id="span4"></span>
<input type="checkbox" id="5" onclick="fun(this)"><span id="span5"></span><script language="javascript">
function fun(box){
if(box.checked){
document.getElementById("span" + box.id).innerHTML = box.id;
}else{
document.getElementById("span" + box.id).innerHTML = "";
}
}
</script>
<input type="checkbox" id="1" onclick="fun(this)"><span id="span1" style="display:none;">1</span>
<input type="checkbox" id="2" onclick="fun(this)"><span id="span2" style="display:none;">2</span>
<input type="checkbox" id="3" onclick="fun(this)"><span id="span3" style="display:none;">3</span>
<input type="checkbox" id="4" onclick="fun(this)"><span id="span4" style="display:none;">4</span>
<input type="checkbox" id="5" onclick="fun(this)"><span id="span5" style="display:none;">5</span><script language="javascript">
function fun(box){
if(box.checked){
document.getElementById("span" + box.id).style.display = "block";
}else{
document.getElementById("span" + box.id).style.display = "none";
}
}
稍改改,实现的方法很多。看你怎么做了
<input type="checkbox" value="1" onclick="fun(this)"><span id="span1"></span><BR>
<input type="checkbox" value="2" onclick="fun(this)"><span id="span2"></span><BR>
<input type="checkbox" value="3" onclick="fun(this)"><span id="span3"></span><BR>
<input type="checkbox" value="4" onclick="fun(this)"><span id="span4"></span><BR>
<input type="checkbox" value="5" onclick="fun(this)"><span id="span5"></span><script language="javascript">
function fun(box){
var sp = document.getElementById("span" + box.value);
if(box.checked){
if (sp.innerHTML == "") sp.innerHTML = 1;
else sp.innerHTML = parseInt(sp.innerHTML,10) +1;
sp.style.display = "";
}
else sp.style.display = "none";
}
</script>