INPUT里面可以用spilt(",")来做个数组操作查找。

解决方案 »

  1.   

    <form method="post" action="">
    <input type="text" name="a" id="a">
    <input type="text" name="b" id="b">
    <input type="text" name="c" id="c">
    <input type="checkbox" name="d" id="d">
    <input type="checkbox" name="e" id="e">
    <input type="radio" name="f" id="f">
    <input type="radio" name="g" id="g">
    <input type="button" name="h" id="h" value="button">
    <input type="submit" name="i" id="i" value="submit">
    <textarea name="j" id="j" rows="4" cols="50"></textarea>
    <input type="text" name="col">
    </form><script language="javascript">
    <!--
    window.onload = function()
    {
    var f = document.forms[0];
    for(i=0;i<f.length;i++)
    {
    if( f.elements[i].type != "hidden" && f.elements[i].name != "col" )
    {
    f.elements[i].onclick=function ()
    {
    if ( f.col.value == "" )
    {
    var col = [];
    col.push( this.id );
    this.style.backgroundColor = "#F00";
    }
    else
    {
    var col = f.col.value.split(",");
    if( col.exsit( this.id ) )
    {
    this.style.backgroundColor = "#FFF";
    col.remove( this.id );
    }
    else
    {
    col.push( this.id );
    this.style.backgroundColor = "#F00";
    }
    }
    f.col.value = col.join(",");
    }
    }
    }
    }
    Array.prototype.exsit = function(v)
    {
    for(i=0;i<this.length;i++)
    {
    if(this[i] == v)
    return true;
    }
    return false;
    }
    Array.prototype.remove = function(v)
    {
    for(i=0;i<this.length;i++)
    {
    if(this[i] == v)
    return this.splice(i,1);
    }
    }
    //-->
    </script>
      

  2.   

    非常感谢,呵呵Thanks very very very much。
    我知道怎么做法,就是不会写,语法不熟悉。惭愧