试图用jquery隐藏一些选项标签不起作用IE,Safari和Opera [英] Trying to hide some options tag with jquery doesn't work IE, Safari and Opera

查看:52
本文介绍了试图用jquery隐藏一些选项标签不起作用IE,Safari和Opera的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用jquery隐藏一些<options>标记,但似乎不起作用.

  • 我想隐藏所有具有rel属性的选项.

  • 仅显示rel='3'

  • 的选项

此代码可用于FF和Chrome.不适用于IE,Safari和Opera.

这是我的jsfiddle:

http://jsfiddle.net/RnfqW/4/

以下是标记和脚本:

<select name="myselect" id="myselect" >
    <option value=''></option>
    <option rel='1' value='1A'>1A</option>
    <option rel='1' value='1B'>1B</option>
    <option rel='2' value='2A'>2A</option>
    <option rel='2' value='2B'>2B</option>
    <option rel='2' value='2C'>2C</option>
    <option rel='3' value='3A'>3A</option>
    <option rel='3' value='3B'>3B</option>
    <option rel='3' value='3C'>3C</option>
    <option rel='3' value='3D'>3D</option>
</select>

脚本:

$("#myselect [rel]").hide(); // hide all options
$("#myselect [rel=3]").show(); // hide whow only rel=3 options

解决方案

您无法隐藏或显示选项.您需要做的就是克隆不需要的选择和删除选项标签.

类似 http://jsfiddle.net/RnfqW/5/

I am trying to hide some <options> tags with jquery but it doesn't seem to work.

  • I want to hide all options that have the rel attribute.

  • Show only options for rel='3'

This code works on FF and Chrome. Doesn't work IE, Safari and Opera.

Here is my jsfiddle:

http://jsfiddle.net/RnfqW/4/

Here is the markup and script:

<select name="myselect" id="myselect" >
    <option value=''></option>
    <option rel='1' value='1A'>1A</option>
    <option rel='1' value='1B'>1B</option>
    <option rel='2' value='2A'>2A</option>
    <option rel='2' value='2B'>2B</option>
    <option rel='2' value='2C'>2C</option>
    <option rel='3' value='3A'>3A</option>
    <option rel='3' value='3B'>3B</option>
    <option rel='3' value='3C'>3C</option>
    <option rel='3' value='3D'>3D</option>
</select>

Script:

$("#myselect [rel]").hide(); // hide all options
$("#myselect [rel=3]").show(); // hide whow only rel=3 options

解决方案

You can't hide or show options. What you must do is clone your select and delete option tags you don't want.

EDIT : something like that http://jsfiddle.net/RnfqW/5/

这篇关于试图用jquery隐藏一些选项标签不起作用IE,Safari和Opera的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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