目前显示床 1、2、3、4
,我需要它显示1、2、3、4 床
,但对于我的生活,我可以不明白怎么办。与 Baths 相同...它当前显示 baths 2+
,我需要它来读取 2+ Baths
。
jQuery:
function bedbathclick() {
var a = $(this).parents(".bed-bath-pop").prev();
var finalString;
var isbaths = false;
if (a.text().indexOf("beds") > -1) {
finalString = " beds ";
} else {
finalString = " baths ";
isbaths = true;
}
$(".bed-bath-pop").find(".popover-content").find("input:checked").each(function(check) {
finalString += $(this).val() + (isbaths ? "+" : "") + ",";
});
finalString = finalString.indexOf(",") > 0 ? finalString.substr(0, finalString.length - 1) : finalString;
a.text(finalString);
}
最佳答案
将单词(beds
或 baths
)存储在另一个变量中以供以后使用(我将其命名为 word
),并将其与您的finalString
在最后。
我会重新安排逻辑,以便在最后确定 beds
或 baths
字符串,但我发现您使用的是 isbaths
连接编号列表时的 bool 值。
function bedbathclick() {
var a = $(this).parents(".bed-bath-pop").prev();
var finalString, word;
var isbaths = false;
if (a.text().indexOf("beds") > -1) {
word = " beds";
} else {
word = " baths";
isbaths = true;
}
$(".bed-bath-pop").find(".popover-content").find("input:checked").each(function(check) {
finalString += $(this).val() + (isbaths ? "+" : "") + ",";
});
finalString = finalString.indexOf(",") > 0 ? finalString.substr(0, finalString.length - 1) : finalString;
a.text(finalString + word);
}
关于javascript - jQuery 移动一些文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41389992/