复选框的问题,高手请来帮忙!
HTML code
<form ACTION="save.asp name="form1">
<table>
<tr>
<td>
<input type="checkbox" name="a" value="abc">
<input type="checkbox" name="b" value="abc">
<input type="checkbox" name="c" value="abc">
<td>
<textarea name="text" cols="60" rows="10" readonly></textarea>
</td>
</tr>
</table>
</form>
我想法是 复选框被选择 则文本域中显示出 其相对应的value值,若取消了 则文本域中的相对应的值 也随即消失,前提是不用刷新页面,用脚本可以实现吗?若可以请附上代码,不尽感激!
------解决方案--------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function fun(){
var ary = document.getElementsByName("a");
var str = "";
for(var i=0;i<ary.length;i++){
if(ary[i].checked){
str = str + ary[i].value;
}
}
document.getElementById("text").value = str;
}
</script>
</HEAD>
<BODY>
<form>
<table>
<tr>
<td>
<input type="checkbox" name="a" value="aaa" onclick = "fun()">
<input type="checkbox" name="a" value="bbb" onclick = "fun()">
<input type="checkbox" name="a" value="ccc" onclick = "fun()">
<td>
<textarea name="text" cols="60" rows="10" readonly></textarea>
</td>
</tr>
</table>
</form>
------解决方案--------------------JScript code
<script type='text/javascript'>
function show(obj){
if(obj.checked == true){
document.getElementsByName('text')[0].value +=obj.value;
}else{
var re = new RegExp("["+obj.value+"]","g");
document.getElementsByName('text')[0].value = document.getElementsByName('text')[0].value.replace(re,"");
}
}
</script>