html-----select 复选框

<html>
       <head>
         <title></title>
            <script>

                     select2str=function(id)
                     {
               var obj=document.getElementById(id);

                        var destobj=document.getElementById(id.replace("sel_",""));

                         var strValue="";
                        for( var i=0; i<obj.options.length; i++)
                        {
                         if( obj.options[i].selected)
                            {
                               strValue+=obj.options[i].value+",";
                            }
                        }
                        strValue=strValue.substring(0,strValue.lastIndexOf(','));
                        destobj.value=strValue;
                        alert(strValue);
                     }
                     bindselect=function(id,strvalue)
                     {
                        var obj=document.getElementById(id);
                        var strs=strvalue.split(",");
                         for( var i=0; i<obj.options.length; i++)
                        {

                         if( isinarray(obj.options[i].value,strs))
                            {
                             obj.options[i].selected=true;
                            }
                        }
                     }
                     isinarray=function(value,arr)
                     {
                         for(var i=0; i<arr.length; i++)
                         {
                            if(value==arr[i])
                             {
                                 return true;
                                }
                         }
                         return false;
                     }

            </script>
       </head>
       <body>
         <select id="sel_cate" size="3" multiple >
             <option value="1">x1</option>
             <option value="2">x2</option>
              <option value="3">x3</option>
                <option value="4">x4</option>
            </select>
            <script>
                     bindselect('sel_cate','1,4');
            </script>
            <input type="text" id="cate" name="cate" />
            <input type="button" id="btnSure" name="btnSure" οnclick="select2str('sel_cate')" />
       </body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值