$(&#; #id option")。hide();不在safari / chrome上工作? [英] $("#id option").hide(); not working on safari/chrome?

查看:167
本文介绍了$(&#; #id option")。hide();不在safari / chrome上工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相同:

  $(#id option)。show(); 

我很惊讶。我认为我的代码出了问题。我尝试了一个空白的html:

 < select id =name> 
< option> 1< / option>
< option> 2< / option>
< / select>

Javascript:

  $(#name option)。hide(); 

< a href =http://jsfiddle.net/kgLkt/ =nofollow> http://jsfiddle.net/kgLkt/



它的作用就像一个用firefox的魅力,但不是在safari和chrome上!



是否有替代品?!

编辑:
我需要隐藏/显示出现在列表中的选项(或其中的一部分)。

解决方案

隐藏:

  var myOpts = $(#id option)。detach ); 

显示:

  $(#id option)。append(myOpts); 

.remove()不同, .detach()保留所有与被删除元素相关联的jQuery数据。


Same for:

$("#id option").show();

I'm just surprised. I thought that something went wrong with my code. I tried it with a blank html:

<select id = "name">
  <option>1</option>
  <option>2</option>
</select>

Javascript:

​$("#name option").hide();​

http://jsfiddle.net/kgLkt/

It works like a charm with firefox, but not on safari nor chrome!

Is there a substitute?!

EDIT: I need to hide/show the option (or some of them) from appearing in the list.

解决方案

To hide:

var myOpts = $("#id option").detach();

To show:

$("#id option").append(myOpts);

As opposed to .remove(), .detach() keeps all jQuery data associated with the removed elements.

这篇关于$(&#; #id option&quot;)。hide();不在safari / chrome上工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆