去除DropDownList的项目使用jQuery一个选项 [英] Removing a option from DropDownList item with jQuery

查看:430
本文介绍了去除DropDownList的项目使用jQuery一个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有其中在一些情况下,一个DropDownList可以包含默认值,该值是不可选的情况下,一旦另一值被改变,则默认值应该不再是一种选择。从我可以告诉,这个观念本身不存在,所以我试图code它使用jQuery。所有这一切都具备这个条件的DropDownLists有一个类valueSkippedHyperSwap分配给他们。需要被去除的值是尖'^'。这里是我有什么,这是不工作:

I have a situation where in some cases a dropdownlist can contain a default value that is not selectable, once another value is changed, the default value should no longer be an option. From what I can tell, this concept does not exist natively, so I am trying to code it up with jQuery. All the DropDownLists which have this condition have a class 'valueSkippedHyperSwap' assigned to them. the value that needs to be removed is the caret '^'. Here is what I have, which is not working:

    $('.valueSkippedHyperSwap').change(function () {
        var node = $(this).has("value='^'");
        node.remove();
    });

每个人的要求,这里是HTML,虽然我不能在我的世界弄清楚如何把它变成一个code座:

per folks request, here is the HTML, though I cannot for the world in me figure out how to get it into a code block:

<!-- snip -->

<div class="questionItem">
<!-- snip -->
<select class="valueSkippedHyperSwap" id="answers_2__Answer" name="answers[2].Answer">
<option selected="selected" value="^">(^) Blank (skip pattern)</option>
<option value="0">(0) No</option>
<option value="1">(1) Yes</option>
<option value="-">(-) Not assessed</option>
</select></div>

<div class="questionItem">
<!-- snip -->
<select class="valueSkippedHyperSwap" id="answers_3__Answer" name="answers[3].Answer">
<option selected="selected" value="^">(^) Blank (skip pattern)</option>
<option value="0">(0) Clear speech-distinct intelligible words</option>
<option value="1">(1) Unclear speech-slurred or mumbled words</option>
<option value="2">(2) No speech-absence of spoken words</option>
<option value="-">(-) Not assessed</option>
</select></div>

<!-- snip -->

其中一个关键的事情,这里要注意的是,有与valueSkippedHyperSwap类名称的多个输入,因此事件中,我们必须使用$(本)罚款正确的选项,不能做其他搜索。

One of the key things to note here is that there is more than one input with the valueSkippedHyperSwap class name, so within the event, we have to use the $(this) to fine the correct option, cannot do another search.

推荐答案

假设你的HTML是这样的

Assuming your HTML is like this

<select id="dd" class="valueSkippedHyperSwap"> 
    <option value="^">None</option>
    <option value="1">One</option>
    <option value="2">Two</option>    
</select>

下面的脚本应删除项值为 ^ 是否有任何其他选项被选中

The below script should remove item with value ^ if any other options are selected

$(function(){

    $('.valueSkippedHyperSwap').change(function () {
       var item=$(this);
      if(item.val()!="^")
      {
        item.find("option[value='^']").remove();
      }
    });            

});

的jsfiddle样品 http://jsfiddle.net/He5gP/10/

这篇关于去除DropDownList的项目使用jQuery一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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