初始化时
allshopid的值为111,222,333
newshopid的值为111,222,333
点击“关闭div1”隐藏div1时,newshopid的值减去shopid1的值,也就是变为222,333
再点击“关闭div2”隐藏div2时,newshopid的值再减去shopid2的值,也就是变为333
再点击“关闭div3”隐藏div3时,newshopid的值再减去shopid3的值,也就是变为空<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>无标题页</title>
    <script type="text/javascript"> 
      this.closeDiv = function(id)
      {      
         $('div' + id).style.display="none"; 
        // $("newshopid") = ?
      }
      this.$=function(obj)
      {
        return document.getElementById(obj);
      }
    </script>
</head>
<body>
    <form id="form1" runat="server">
     <input type="text" id="newshopid" name="newshopid" value="111,222,333" style="width:800px"/> 
     <input type="text" id="allshopid" name="allshopid" value="111,222,333" style="width:800px" />
     <br />
      <div id="div1">
         <input type="hidden" id="shopid1" name="shopid1" value="111" />
         <div style="cursor: pointer" onclick="closeDiv('1')">关闭div1</div>
       </div>
       <div id="div2">
           <input type="hidden" id="shopid2" name="shopid2" value="222" />            
         <div style="cursor: pointer" onclick="closeDiv('2')">关闭div2</div>
       </div>
      <div id="div3">
         <input type="hidden" id="shopid3" name="shopid3" value="333" />                
         <div style="cursor: pointer" onclick="closeDiv('3')">关闭div3</div>     
       </div>   
    </form>
</body>
</html>

解决方案 »

  1.   

    closeDiv('111')这里把id传过去然后替换
      

  2.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>无标题页 </title>
        <script type="text/javascript">
          this.closeDiv = function(id)
          {     
            $('div' + id).style.display="none";
            $("newshopid").value=(id<3)?$("newshopid").value.replace($('shopid' + id).value+',',''):$("newshopid").value.replace($('shopid' + id).value,'');
          }
          this.$=function(obj)
          {
            return document.getElementById(obj);
          }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <input type="text" id="newshopid" name="newshopid" value="111,222,333" style="width:800px"/>
        <input type="text" id="allshopid" name="allshopid" value="111,222,333" style="width:800px" />
        <br />
          <div id="div1">
            <input type="hidden" id="shopid1" name="shopid1" value="111" />
            <div style="cursor: pointer" onclick="closeDiv('1')">关闭div1 </div>
          </div>
          <div id="div2">
              <input type="hidden" id="shopid2" name="shopid2" value="222" />           
            <div style="cursor: pointer" onclick="closeDiv('2')">关闭div2 </div>
          </div>
          <div id="div3">
            <input type="hidden" id="shopid3" name="shopid3" value="333" />               
            <div style="cursor: pointer" onclick="closeDiv('3')">关闭div3 </div>   
          </div> 
        </form>
    </body>
    </html> 
      

  3.   

    把input的id传过去,得到他的value值,再对value值操作