簡體   English   中英

dynamicall使用javascript單擊鼠標時添加p元素

[英]dynamicall add p element on mouse click using javascript

我需要一個代碼來使用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>

檢查您的函數名稱替換此

onclick="addElement()"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM