<select name="id[48]" id="attrib-48"> 
  <option value="269" selected="selected">Normal</option> 
  <option value="270">Rush</option> 
</select> 我想直接在显示的时候把<option value="270">Rush</option> 隐藏掉,也就是不展示在网站上。
ps.由于种种原因,这个选项需保留在代码中。
请问如何用js实现?

解决方案 »

  1.   


    <!--<option value="270">Rush </option> -->注释掉,可以么?
      

  2.   

    不知道LZ是什么需求 
    在代码中保留? 可不可以考虑在加载后把<option value="270">Rush </option>
    这项Remove ?
      

  3.   

    #2搂正解document.getElementById('attrib-48').Options[1].style.display = 'none';
      

  4.   

    L@_@K
    <!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <style type="text/css">  </style>
     </head> <body>
    <select name="id[48]" id="attrib-48">
    <option value="269" selected="selected">Normal </option>
    <option value="270">Rush </option>
    </select>
     </body>
     <script type="text/javascript" defer>
     <!--
    var sel = document.getElementById("attrib-48");
    sel.options.remove(sel.options.length-1);
     //-->
     </script>
    </html>
      

  5.   

    请注意,option 根本没有 display 这个样式!!!
      

  6.   

    通过DOM树结构,将这个选项设定成不显示。
    document.getElementById('attrib-48').Options[1].style.display = 'none';
      

  7.   

    6楼的是remove了。
    行倒是行,可以赋给window的一个属性。要的时候再appendChild。
      

  8.   

    <input type="radio" name="id[26]" value="212" id="attrib-26-212" /><label class="attribsRadioButton zero" for="attrib-26-212">rush</label>
    这种情况如何把这些都隐藏掉呢ps.后面的label不能用那个class隐藏
      

  9.   


    又有个问题诶,这个东西在firefox下面不行啊
      

  10.   

    你的目的是不显示这个值,那就把这个option的text的值放到一个自定义属性中,然后把这项的值清空<!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <style type="text/css">  </style>
     </head> <body>
        <select name="id[48]" id="attrib-48">
            <option value="269" selected="selected">Normal </option>
            <option value="270">Rush </option>
        </select>
     </body>
     <script type="text/javascript" defer>
     <!--
    var sel = document.getElementById("attrib-48");
    //sel.options.remove(sel.options.length-1);
    sel.options[1].setAttribute("txt",sel.options[1].text);
    sel.options[1].text="";
    alert("值藏起来了:"+sel.options[1].getAttribute("txt"));
     //-->
     </script>
    </html>
      

  11.   

    用jquery 就简单了
    先找到select  然后找到你需要隐藏的children()
    直接 .hide()
      

  12.   

    或者,将那个option整个outerHTML注释掉!
    <!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>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <style type="text/css">  </style>
     </head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    /** 
    * 兼容firefox的 outerHTML 使用以下代码后,firefox可以使用element.outerHTML 
    **/ 
    if(window.HTMLElement) { 
    HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){ 
    var r=this.ownerDocument.createRange(); 
    r.setStartBefore(this); 
    var df=r.createContextualFragment(sHTML); 
    this.parentNode.replaceChild(df,this); 
    return sHTML; 
    }); 
    HTMLElement.prototype.__defineGetter__("outerHTML",function(){ 
    var attr; 
    var attrs=this.attributes; 
    var str="<"+this.tagName.toLowerCase(); 
    for(var i=0;i<attrs.length;i++){ 
    attr=attrs[i]; 
    if(attr.specified) 
    str+=" "+attr.name+'="'+attr.value+'"'; 

    if(!this.canHaveChildren) 
    return str+">"; 
    return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">"; 
    }); 
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){ 
    switch(this.tagName.toLowerCase()){ 
    case "area": 
    case "base": 
    case "basefont": 
    case "col": 
    case "frame": 
    case "hr": 
    case "img": 
    case "br": 
    case "input": 
    case "isindex": 
    case "link": 
    case "meta": 
    case "param": 
    case "select":
    case "option":
    return false; 

    return true; 
    }); 

    //-->
    </SCRIPT>
     <body>
        <select name="id[48]" id="attrib-48">
            <option value="269" selected="selected">Normal </option>
            <option value="270">Rush </option>
        </select>
     </body>
     <script type="text/javascript" defer>
     <!--
    var sel = document.getElementById("attrib-48");
    sel.options[1].outerHTML="<!-- "+sel.options[1].outerHTML+" -->";
     //-->
     </script>
    </html>
      

  13.   

    js 实现:var temp = document.getElementById("attrib-48");
             temp.style.display = "none";
    JQuery 实现:$('#attrib-48').css("display","none");