js 实现多选

来源:互联网 发布:java 接口定义变量 编辑:程序博客网 时间:2024/04/28 08:30

<title>无标题页</title>
    <script  type="text/javascript" src="pageScript.js"> </script>
    <script type="text/javascript">
   function open1(hiden){
       window.open("sub.aspx?hiden="+hiden,"newwindow","height=100,width=200,top=200,left=300");
    }
    //清除选择项
function Cel(_Value,showText,showValue)
{
    var Array_value = document.getElementById(showValue).value.split("|");
    var Array_text = document.getElementById(showText).innerHTML.split("|");
    var existed = 0;
    for(i=0;i < Array_value.length;i++){
      //  if(_Value.replace(/_/ig,"-")==Array_value[i].replace(/_/ig,"-"))
        {
            Realign(i,showText,showValue);
            break;
        }
    }
}
//重新排列选项
function Realign(value,showText,showValue){
    var Array_value = document.getElementById(showValue).value.split("|");
    var Array_text = document.getElementById(showText).innerHTML.split("|");
    Array_text[value]="";
    Array_value[value]="";
    document.getElementById(showText).innerHTML = "";
    document.getElementById(showValue).value = "";
    for(j=0;j<Array_text.length;j++){
        if(Array_text[j]!="")
            document.getElementById(showText).innerHTML +=Array_text[j]+"|";
    }
    for(e=0;e<Array_value.length;e++){
        if(Array_value[e]!="")
            document.getElementById(showValue).value +=Array_value[e]+"|";
    }
}
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="tb_usePeople" runat="server" Text="Label"></asp:Label>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:HiddenField ID="HF_Value" runat="server" />
    </div>
    </form>
</body>
</html>

 protected void Page_Load(object sender, EventArgs e)
    {
        //初始化有多少人
        string value = "";
        if(HF_Value.Value!=null)
            value=HF_Value.Value;
        if (!IsPostBack)
        {
            value = "qq|ww|yy|";
            HF_Value.Value = value;
        }
        tb_usePeople.Text = GetUsers(value, "tb_usePeople", "HF_Value");
            Button1.Attributes.Add("onclick","javascript:open1('"+value+"')");
    }
    public String GetUsers(string strid, string ctl_Text, string Ctl_Value)
    {
        string[] Arrayid = strid.Split('|');
        string manageList = "";
        if (Arrayid.Length > 0)
        {
            for (int i = 0; i < Arrayid.Length - 1; i++)
            {
                if (Arrayid[i].ToString() != "")
                {
                    string strUrl = "<a href='#'onclick='Cel(/"" + Arrayid[i].ToString() + "/",/"" + ctl_Text + "/",/"" + Ctl_Value + "/")'><img id='image' src='bs.jpg' alt='取消'/></a>";
              
                    manageList += Arrayid[i].ToString() + strUrl + "|";
                }
            }
        }
        else{
        manageList="";
        }
        return manageList;
    }

  <title>无标题页</title>
    <script>
   
    //向母页传输信息,多项选择
    function ReturnValue(_text,_value){
   
   
    var showtext="tb_usePeople";
    var showvalue=opener.document.getElementById("HF_Value").value;
    var strUrl=  "<a href='#'onclick='Cel(/"" + _value + "/",/"" +showtext + "/",/"HF_Value/")'>";
                strUrl+="<img id='image' src='bs.jpg' alt='取消'><a/>";
      
       if(opener!=null)
       {
      
       if(showtext!="")
       {
       var begin=0;
       var Array_value=showvalue.split("|");
       for(e=0;e<Array_value.length;e++)
          { 
          if(Array_value[e]!="")
          if(Array_value[e]==_value){
          begin=1;
          break;}
          }
          if(begin==0)
          {
          if(_text!="")
          opener.document.getElementById("tb_usePeople").innerHTML+=_text+strUrl+"|";
          if(_value!="")
          {
          opener.document.getElementById("HF_Value").value+=_value+'|';
          }
          }
          else{alert(_text+"已被选择!");}
       }
      
       }
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a href="#" onclick="ReturnValue('haha','haha')">haha</a><br />
     <a href="#" onclick="ReturnValue('nana','nana')">nana</a><br />
      <a href="#" onclick="ReturnValue('qw','qw')">qw</a><br />
      <asp:HiddenField ID="ShowValue" runat="server"/>
    </div>
    </form>
</body>
</html>
 protected void Page_Load(object sender, EventArgs e)
    {
        ShowValue.Value = Request.QueryString["hiden"].ToString();
    }

原创粉丝点击