<input type=checkbox onclick="showName(this);" name="checkbox111">
<input type=checkbox onclick="showName(this);" name="checkbox222">
<input type=checkbox onclick="showName(this);" name="checkbox333">
<input type=checkbox onclick="showName(this);" name="checkbox444">
<input type=checkbox onclick="showName(this);" name="checkbox555">
<input type=checkbox onclick="showName(this);" name="checkbox666">
<input type=checkbox onclick="showName(this);" name="checkbox777">
<br>
<textarea name="t1" rows=5 cols=50>
</textarea>
<script>
function showName(obj){
var iPos=document.all.t1.value.indexOf(obj.name);
if(obj.checked)
{if(iPos==-1)
document.all.t1.value+=obj.name;}
else
{
if(iPos!=-1)
document.all.t1.value=document.all.t1.value.replace(obj.name,'');
}
}
</script>

解决方案 »

  1.   

    <style>
    input{t:expression(this.onclick=set);width:expression(this.scrollWidth)}
    </style>
    <script>
    function set()
    {
      var o=document.getElementsByTagName('input');
      var rs=document.getElementById('result');
      rs.value='';
      for(var i=0;i<o.length;i++)
       {
         if(o[i].checked)
           rs.value+=(o[i].name+'  ');
       }
    }
    </script>
    <body><input type=checkbox onclick="showName(this);" name="checkbox111">
    <input type=checkbox onclick="showName(this);" name="checkbox222">
    <input type=checkbox onclick="showName(this);" name="checkbox333">
    <input type=checkbox onclick="showName(this);" name="checkbox444">
    <input type=checkbox onclick="showName(this);" name="checkbox555">
    <input type=checkbox onclick="showName(this);" name="checkbox666">
    <input type=checkbox onclick="showName(this);" name="checkbox777"><input type=text id='result'>
    </body>
    <script></script>
      

  2.   

    copy了一下美裤子的input元素,忘了去掉onclick属性
    <style>
    input{t:expression(this.onclick=set);width:expression(this.scrollWidth)}
    </style>
    <script>
    function set()
    {
      var o=document.getElementsByTagName('input');
      var rs=document.getElementById('result');
      rs.value='';
      for(var i=0;i<o.length;i++)
       {
         if(o[i].checked)
           rs.value+=(o[i].name+'  ');
       }
    }
    </script>
    <body><input type=checkbox  name="checkbox111">
    <input type=checkbox  name="checkbox222">
    <input type=checkbox  name="checkbox333">
    <input type=checkbox  name="checkbox444">
    <input type=checkbox  name="checkbox555">
    <input type=checkbox  name="checkbox666">
    <input type=checkbox  name="checkbox777"><input type=text id='result'>
    </body>
    <script></script>