批改状态:合格
老师批语:
const comment = document.querySelector('.comment');const content = comment.content;const submitBtn = comment.submit;const commentList = document.querySelector('.list');添加字数,限制字符,新留言前置submitBtn.onclick = (ev) => {let value = content.value.trim();if (value.length > 0 && value.length <= 100) {const newComment = document.createElement("li");newComment.textContent = value;newComment.style.borderBottom = "1px solid white";newComment.style.minHeight = "3em";新留言前置,留言成功commentList.prepend(newComment);alert("left message successful");清空留言,无内容或超字数content.value = null;content.focus();} else {alert("no content or too many words");content.focus();return false;}};添加删除留言buttonnewComment.append(deleteBtn);const deleteBtn = document.createElement(“button”);deleteBtn.textContent = “delete”;deleteBtn.style.float = “right”;deleteBtn.classList.add(“del-btn”);确定是否删除deleteBtn.onclick = function () {if (confirm(“are you sure delete”)) {this.parentNode.remove();alert("delete successful");content.focus();return false;}};
2. 字符串和数组
concat()拼装
slice(start, end)取子串
substr(start, size): 取子串
trim(): 删除字符串二边的空白字符
将字符串打散成数组
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号