我运行的是以下几点:如何从字符串中剥离字符串并将其推入数组?
var countries = [];
$("#usp-custom-3 option").each(function() {
var single = $(this).text();
if($(single == "United States of America")) {
$(this).text() == "United States";
}
countries.push(single);
console.log(single);
});
基本上,我试图做的是United States of America
转化为United States
之前,将其与其余国家推入阵在一起,因为我有个国家的名单select option
。
也许'单== “美国”;'?因为单个是你传递给你的数组的对象 –
推''(this).text()'而不是单独的,因为你没有分配到'单' – Durga
为什么downvote? –