本帖最后由 spyq_1992 于 2013-11-24 06:43:42 编辑

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function selectUser(userId){
        var e=document.getElementById("a");
    //通过id找到input的位置
    //    e.value=e.value+e.value.indexOf(userId);
        //上面语句显示,e.value.indexOf(userId)的值为-1
         
        if( e.value.indexOf(userId) == -1){
            //看是不是input里面已经含有该用户id
            e.value=e.value+userId+',';
            //如果没有含有,那么在input位置加上新的id和逗号
        }else{
            e.value.replace(userId+",","");  
            //如果input已经含有了该id那么就把这个id从input里面除去
        }     
    }
    </script>
    </head><body>
    <input type="text" onblur="selectUser('a')" id='a'/>
    </body>
    </html>
    else判断里多了个)