我可以得到很好的结果,但是每个数据值结果都用逗号分隔,因为它是一个数组。我想在没有任何逗号的情况下进行查询,并可能删除最后一个 AND。
那可能吗 ?
jQuery
//Submit Adv Search
$('#submitAdvSearch').click(function(){
var query = "SELECT * FROM table WHERE ";
var yo = $('.subCat span[data-value].checked').map(function(){
return $(this).attr('data-value')+'=1 AND ';
}).get();
console.log(query+' '+yo);
});
HTML
<div class="cat">
<div class="catTitle">
<h2>Performance</h2>
<span class="arrow"></span>
<br class="clear"/>
</div>
<div class="subCat" data-cat="performance">
<div>
<span data-all="all">○ Tous</span><br>
<div class="after">
<span data-value="30000_doublefrotements" class="checked">○ +30,000 double frottement</span><br>
<span data-value="atcc96_lavablecommercial">○ ATTCC 96</span><br>
<span data-value="nfpa701_inifuge">○ NFPA 701</span><br>
<span data-value="resistanrayonsuv">○ Uv résistant</span>
</div>
</div>
</div>
</div>
<div class="cat">
<div class="catTitle">
<h2>Style</h2>
<span class="arrow"></span>
<br class="clear"/>
</div>
<div class="subCat" data-cat="style">
<div>
<span data-all="all">○ Tous</span><br>
<div class="after">
<span data-value="contemporain" class="checked">○ Contemporain</span><br>
<span data-value="traditionnel">○ Traditionel</span><br>
<span data-value="transitionnel" class="checked">○ Transitionel</span>
</div>
</div>
</div>
</div>
<div id="submitAdvSearch">Submit</div>
结果
SELECT * FROM table WHERE 30000_doublefrotements=1 AND ,contemporain=1 AND ,transitionnel=1 AND