我想创建动态切换台和创建和按钮对象与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>
嗨阿里,你需要在这里对堆栈溢出您的文章的代码 - 不只是链接到第三方网站。 –