0

我需要一个代码来使用 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>
4

1 回答 1

0

检查你的函数名替换这个

onclick="addElement()"
于 2012-09-11T06:00:02.233 回答