1 回答

TA貢獻(xiàn)1786條經(jīng)驗 獲得超11個贊
<body>
<ul class="oUl"><li>1</li><li>2</li><li>3</li><li>4</li></ul>
<input class="oBtn" type="button" value="按鈕">
</body>
<script>
var oBtn = document.getElementsByTagName("input")[0];
oBtn.onclick = append;
function append() {
var oUl = document.getElementsByTagName("ul")[0];
var cRlitextnode = parseInt(oUl.lastChild.innerText);
cRlitextnode++;
console.log(cRlitextnode);
var li = document.createElement("li");
var textNode = document.createTextNode(cRlitextnode);
oUl.appendChild(li);
li.appendChild(textNode);
}
</script>
li要寫成一行的,空白節(jié)點也是節(jié)點,以上是測試通過的代碼
添加回答
舉報