Javascript 如何在每次单击按钮时创建新的DIV?

Javascript 如何在每次单击按钮时创建新的DIV?,javascript,html,Javascript,Html,我正在尝试创建一个具有100x100 px的DIV,它应该是红色的,每次单击按钮时,我都会执行以下代码,但它不起作用: <html> <title> create new div </title> <body> <button id="createsquare"> Cria QUADRADO </button> <script> function fcreatesquare() { var c

我正在尝试创建一个具有100x100 px的DIV,它应该是红色的,每次单击按钮时,我都会执行以下代码,但它不起作用:

    <html>
<title>
    create new div
</title>

<body>
<button id="createsquare">
Cria QUADRADO
</button>

<script>
function fcreatesquare()
{
var crsq = document.createElement('div', 'id=created', 'widght=100px', 'wheidght=100px','color=black');
return crsq;
}

    var createsquare = document.getElementById('createsquare');
    createsquare.onclick(fcreatesquare);
</script>
</body>

</html>

创建新div
克里亚夸德拉多酒店
函数fcreatesquare()
{
var crsq=document.createElement('div','id=created','width=100px','wheidth=100px','color=black');
返回crsq;
}
var createsquare=document.getElementById('createsquare');
onclick(fcreatesquare);

查看
appendChild
功能:


这回答了你的问题吗?
function fcreatesquare() {
var crsq = document.createElement('div', 'id=created', 'widght=100px', 'wheidght=100px','color=black');
document.getElementsByTagName("body")[0].appendChild(crsq);
}