我有一個查詢,我填充菜單和過濾項所以我的代碼類替代格式
function completeGalleryCat(data, target, eng) {
var items = data.d.results;
var prefix = "";
var sufix = "<div class='clear'></div>";
if (eng)
prefix = "<div class='filter selected' data-category='cat-all'>All</div>";
else
prefix = "<div class='filter selected' data-category='cat-all'>Todas</div>";
var menu = "";
var cat = "";
for (var item in items) {
if (eng)
cat = items[item].English;
else
cat = items[item].Title;
menu += "<div class='filter' data-category='" + cat.replace(" ", "_").replace(/[^\w\s]/gi, '') +"'>"+ cat +"</div>";
}
$(target).html(prefix + menu + sufix);
}
所以,你可以看到,我更換空間下劃線,如:
menu += "<div class='filter' data-category='" + cat.replace(" ", "_").replace(/[^\w\s]/gi, '') +"'>"+ cat +"</div>";
問題是,當我有3個短語,如
<div class="filter" data-category="Transporting_of Materials">Transporte de Materiales</div>
正如你可以看到我有一個丟失的下劃線在data-category="Transporting_of Materials"
Thankyou提前
它的工作原理,我只能更換這一行'菜單+ = 「