2013-03-12 24 views
1

后剩下这是JS我有:清除的DIV的使用从下拉列表中选择的jQuery

<script type="text/javascript"> 
     $(document).ready(function(){ 
      $('#box1').hide(); 
      $('#box2').hide(); 
      $('#box3').hide(); 
      $("#thechoices").change(function(){ 
       if(this.value == 'all'){ 
        $("#boxes").children().show(); 
        }else{ 
        $("#" + this.value).show().siblings().hide(); 
        } 
      });   
      $("#thechoices").change(); 
     }); 
</script> 

和HTML:

<div id="boxes"> 
     <div id="box1"><p>Box 1 stuff…</p></div> 
     <div id="box2"><p>Box 2 stuff…</p></div> 
     <div id="box3"><p>Box 3 stuff…</p></div> 
    </div> 

我需要从下拉列表中选择后清除(清空)所有其他选项, (即使我打开源代码,他们也不会ap梨),并在同一时间禁用下拉列表,

如何实现?

+0

是否要将它们从页面中完全删除或只是将它们留空。如果你想让它们变为空白,可以这样做: $('#thechoices')。empty(); – iAmClownShoe 2013-03-12 19:13:17

+1

而且,javascript(jquery)无法从源代码中删除元素,只有DOM。见http://stackoverflow.com/questions/2185760/jquery-does-remove-really-remove – 2013-03-12 19:14:33

+0

是的,他是正确的,它不会从源代码删除它,只有dom – iAmClownShoe 2013-03-12 19:16:34

回答

0

我认为这应该可以做到。

$(document).ready(function(){ 
    $('#thechoices').change(function(){ 
     $(this).empty(); 
    }); 
}); 
+0

这将摆脱所有选项,而不仅仅是他不想要的选项。 – BBagi 2013-03-12 19:20:21

+0

@RuralJuror “我需要从下拉列表中选择清除(空)所有其他选项” - OP – iAmClownShoe 2013-03-12 19:21:20

+0

再次阅读,小丑:“*休息*的选项,而不是所有的选项.. 。“-OP – BBagi 2013-03-12 19:21:53

相关问题