我想創建動態切換臺和創建和按鈕對象與jQuery和一些動態變量爲此然後我希望Html對象追加到Html我不能這樣做下面鏈接是我的代碼 訪問jsfiddle。淨/ eu3a0k3m/2/創建動態切換臺
我的js代碼:
var count = 3;
$("#btn").click(function(){
CreateInlineChildWithSwitchery(++count);
});
function CreateInlineChildWithSwitchery (countOfChilds){
var Integer_LastSwitcheryId = count;
var btn = $('<input type="checkbox" id="js-switch' + Integer_LastSwitcheryId + '" class="js-switch' + Integer_LastSwitcheryId + ' js-check-change' + Integer_LastSwitcheryId + ' col-lg-3" data-switchery="true">');
console.log(btn)
$('#all-encyclopedia').append(
$("#tpl ").html()
.replace(/{switchery}/g,btn)
);
eval("elem" + Integer_LastSwitcheryId.toString() + "=document.querySelector('#js-switch"+Integer_LastSwitcheryId.toString()+"')");
eval("switchery" + Integer_LastSwitcheryId.toString() +"={elem" + Integer_LastSwitcheryId.toString() + ", color: '#1AB394',secondaryColor: '#688ab0'}");
eval("changeCheckbox" + Integer_LastSwitcheryId.toString() + "=document.querySelector('.js-check-change"+Integer_LastSwitcheryId.toString()+"')");
eval("changeField" + Integer_LastSwitcheryId.toString() + "=document.querySelector('.js-check-change-field"+Integer_LastSwitcheryId.toString()+"')");
}
for(i=1;i<4;i++)
CreateInlineChildWithSwitchery(count++);
我的HTML代碼:
<script type="text/tpl" id="tpl">
{switchery}
</script>
<button id="btn">insert Switchery</button>
<div id="all-encyclopedia"></div>
嗨阿里,你需要在這裏對堆棧溢出您的文章的代碼 - 不只是鏈接到第三方網站。 –