0

我将如何向该语句添加另一个要按值评估的元素?

if ($(this).val() == 1 && !$(this).data("priority1"))?

我想使用 class 作为这个新元素的选择器(在这种特殊情况下,class="complaint" 并且其中一个值是“Too_small”)

我已经尝试过(带和不带括号)

if ($('.complaint').val() === "Too_small" && $(this).val() == 1 && !$(this).data("priority1")) 

我已经包含了下面的函数,以及一个工作示例 http://jsfiddle.net/chayanyc/Dhaat/225/

var $priority1 = $(".priority1");
$(".features_rank1").change(function() {
    var name = $(this).data("name"); //get priority name
    if ($(this).val() == 1 && !$(this).data("priority1")) {
        //rank is 1, and not yet added to priority list
        $("<option>", {text:name, val:name}).appendTo($priority1);
        $(this).data("priority1", true); //flag as a priority item
    }
    if ($(this).data("priority1") && $(this).val() != 1) {
        //is in priority list, but now demoted
        $("option[value=" + name + "]", $priority1).remove();
        $(this).removeData("priority1"); //no longer a priority item
    }
});
4

1 回答 1

1

尝试:

$(".complaint select").val()

您需要类select下标签的值.complaint

但是,您有两个属于 类的元素.complaint,因此您需要弄清楚您想要哪一个。

于 2012-11-20T18:49:50.050 回答