如何使用列表變量創建大廈HTML ...JQUERY - 建築用HTML列表變量
這是我的代碼錯誤...
HTML
<div class="demo">
<!-- append code -->
</div>
CSS
.demo_btn_btn1 {
color :red;
}
.demo_btn_btn2 {
color :blue;
}
.demo_btn_btn3 {
color :orange;
}
jQuery代碼
$(function(){
var cls = ['btn1','btn2','btn3'],
txt = ['button1','button2','button3'],
html = [];
html = $('<button class="demo_btn_' + cls + '"><span>' + txt + '</span></button>');
$(".demo").append(html);
});
這個輸出我的代碼
<div class="demo">
<button class="demo_btn_btn1,btn2,btn3">
<span>button1,button2,button3</span></button>
</div>
,我想這...
<div class="demo">
<button class="demo_btn_btn1"><span>Button1</span></button>
<button class="demo_btn_btn2"><span>Button2</span></button>
<button class="demo_btn_btn3"><span>Button3</span></button>
</div>
請HEL p我,謝謝你提前
的[構建html元素jQuery中最清楚的方式]可能的複製(https://stackoverflow.com/questions/9760328/clearest-way-to-build-html-elements-in-jquery) – BravoZulu