js动态往div里添加按钮的两种方式


方式1:
var MyDiv =document.getElementById("div_id");
var button = document.createElement("input");
button.setAttribute("type", "button");
button.setAttribute("value", value);
button.setAttribute("id", id);
button.setAttribute("class", class);
button.style.width = "12%";
button.setAttribute("onclick", "function(this.id)");
MyDiv.appendChild(button);


方式2:
var button = "<a role='button' id="+jinfo[i].id+" onclick='function(this.id)'><i class='icon-edit'></i></a>";
MyDiv.innerHTML += button;


//第二种方式方便往<a></a>标签之间添加内容


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM