如果“.ranking”或“.complaint select”发生更改,如何触发此功能?
当用户选择投诉并对问题的重要性级别进行排序时,此更改功能会在“increase_priority1”中添加和/或删除值。目前,它仅在“排名”更改时触发,因此如果用户更改问题而不更改重要性级别,则不会相应地更改值。
var $increase_priority1 = $(".increase_priority1");
// If value is "Shoulders", complaint was Shoulders too small (select name=Shoulders value=Too_small) and it was assigned a level 1 priority (select class="ranking shoulders" value=1).
// var's for other issues and priority levels go here
$(".ranking, .complaint select").change(function () {
var name = $(this).data("name"); //get priority name
if ($(".complaint select").val() === "Too_small" && $(this).val() == 1 && !$(this).data("increase_priority1")) {
//rank is 1, and not yet added to priority list
$("<option>", {
text: name,
val: name
}).appendTo($increase_priority1);
$(this).data("increase_priority1", true); //flag as a priority item
}
if ($(this).data("increase_priority1") && ($(this).val() != 1 || $(".complaint select").val() != "Too_small")) {
//is in priority list, but now demoted
$("option[value=" + name + "]", $increase_priority1).remove();
$(this).removeData("increase_priority1"); //no longer a priority item
}
// Similar If Statements to set & unset other elements go here
});
有多个投诉和排名元素,反映了客户投诉的各个领域,并以 1 - 5 的等级进行排名。
小提琴在上下文中显示了这一点:http: //jsfiddle.net/chayacooper/vWLEn/168/