gpt4 book ai didi

javascript - 想要显示选择的重复排名以及使用 javascript/jquery 重复的排名

转载 作者:太空宇宙 更新时间:2023-11-04 11:25:26 24 4
gpt4 key购买 nike

这里我们添加了逻辑来显示哪些排名重复,但我也想准确显示哪个排名重复。排名从 0 到 18。

function validate(sdd_ejrp_form) 
{
var duplicateRanksDetected = false;
var validate_rank_str = ",";
jq("\[data-dom-id=gsc-containers\]").find("\[data-dom-id=gsc-container\]").each(function (index)
{ var jqThis = jq(this);
var gsc_uri = jqThis.attr("data-gsc-data-gsc-uri");
var prof_lvl_rank = jqThis.find("select\[name='prof-lvl-rank'\]").val();
jqThis.find("\[data-dom-id=proficiency-level\]").each(function (index2)
{
var btn = jq(this);
if (btn.hasClass("active"))
{
if (validate_rank_str.indexOf("," + prof_lvl_rank + ",") != -1)
{
duplicateRanksDetected = true;
return false;
} else
{
validate_rank_str += prof_lvl_rank + ",";
}
}
});
});

if (duplicateRanksDetected == true)
{
// here I want to display exactly which rank is duplicated
alert("Duplicate ranks detected!");
return false;
}
}
}

最佳答案

只需进行 3 处修改即可轻松完成:

function validate(sdd_ejrp_form) {

var duplicateRanksDetected = []; //create an array here

var validate_rank_str = ",";
jq("\[data-dom-id=gsc-containers\]").find("\[data-dom-id=gsc-container\]").each(function(index) {
var jqThis = jq(this);
var gsc_uri = jqThis.attr("data-gsc-data-gsc-uri");
var prof_lvl_rank = jqThis.find("select\[name='prof-lvl-rank'\]").val();
jqThis.find("\[data-dom-id=proficiency-level\]").each(function(index2) {
var btn = jq(this);
if (btn.hasClass("active")) {
if (validate_rank_str.indexOf("," + prof_lvl_rank + ",") != -1) {

duplicateRanksDetected.push(prof_lvl_rank); // fill the array here

return false;
} else {
validate_rank_str += prof_lvl_rank + ",";
}
}
});
});

if (duplicateRanksDetected.length > 0) {
// here I want to display exactly which rank is duplicated
alert(
"Duplicate ranks detected: " +
duplicateRanksDetected.join(', ') // display the result here
);
return false;
}
}

关于javascript - 想要显示选择的重复排名以及使用 javascript/jquery 重复的排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44426141/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com