我需要一个代码,使用JavaScript
在按钮的每个onclick事件上显示一些消息 enter code here
<!DOCTYPE>
<html>
<head>
<script>
function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my'+num+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = 'Element Number '+num+' has been added! <a href=\'#\' onclick=\'removeElement('+divIdName+')\'>Remove the div "'+divIdName+'"</a>';
ni.appendChild(newdiv);
}
</script>
</head>
<body>
<div id='myDiv'>
<input type="button" value="click" onclick="addelement()">
<p id='theValue'></p>
</div>
</body>
</html>
答案 0 :(得分:0)
检查您的功能名称 替换这个
onclick="addElement()"