sun201200204 发表于 2013-2-7 17:33:06

js中option操作

 
<html>   <head>   <script language="javascript">var infoMap= new Object() ;function number(){   var obj = document.getElementById("mySelect");    //obj.options = new Option("我的吃吃","4");      //在当前选中的那个的值中改变       //obj.options.style.cssText =("background:red");    obj.options.add(new Option("我的吃吃","4"));//再添加一个option    //alert(obj.length);    obj.options.style.cssText =("background:#66FF33");    /*    for (var i = 0; i < obj.length; i++) {    obj.options.add(new Option(obj, obj));    }    */    //alert(obj.selectedIndex);//显示序号,option自己设置的    /*    var name = obj.options.text;    infoMap = {      name : name,      age : '1'    };    if( infoMap ) {      var oldname = infoMap.name;      infoMap.name = oldname+','+name;    }    alert(infoMap.age);    */    //obj.options.text = "我的吃吃";更改值      //obj.remove(obj.selectedIndex);//删除功能   }   </script>   </head>   <body>   <select id="mySelect" multiple>      <option title='hello' selected>我的包包</option>      <option style="background:red" value="#333333">我的本本</option>      <option>我的油油</option>      <option>我的担子</option>   </select></p><p style="color:#fff;background:#780e1a;">Test for set style.</p><p><button >set style(op only)</button></p><p><button >set style(ff & ie)</button></p><p><button >set style(ff & op)</button></p><p><button >set style(ie only)</button></p><p><input type="button" name="button" value="查看结果" >   </body>   </html> 
 
 
页: [1]
查看完整版本: js中option操作