2012-09-11 40 views
0

在鼠標單擊添加p元素我需要一個代碼,在使用JavaScriptdynamicall使用JavaScript

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

一個按鈕,每一個onclick事件顯示一些消息,請檢查您的函數名 替換該

onclick="addElement()"