前端疑问集合
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> window.onload = function () { // 1.textarea标签中的value:提交给服务器的值 var oTarea = document.getElementById("content"); var oLiuyan = document.getElementById("liuyan"); var oFm = document.getElementById('fm'); var oUl = document.createElement("ul"); oFm.parentNode.appendChild(oUl); oLiuyan.onclick = function () { for(i=0;i<2;i++){ var oLi = document.createElement('li'); oLi.innerHTML = 'aaaa'+'<span>X</span>'; oUl.appendChild(oLi); } // oUl.style.display = 'inlineblock'; }; }; </script> <style> *{ margin: 0; padding: 0; } #ctn{ width: 300px; height: 500px; border: 1px solid red; text-decoration: none; color: black; } </style> </head> <body> <h3>简易留言板</h3> <form action="" id="fm"> <textarea rows="3" cols="20" id="content" name="text" ></textarea> <!-- 使用<button></button>不能给li加内容 <button type="submit" id="liuyan">留言</button>--> <input type="button" id="liuyan" value="留言"> <button type="button" id="sum">统计</button> </form> <div id="box"></div> </body> </html>
使用<button></button>时, 给其加入onclick时间并给'li'标签设置innerHTML属性后, 点击时只闪现li标签的内容, 不固定显示