Js实现无刷新删除内容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>仿腾讯微博效果</title> <style type="text/css"> body,div,h2,h3,ul,li,p{margin:0;padding:0;} a{text-decoration:none;} a:hover{text-decoration:underline;} ul{list-style-type:none;} body{color:#333;background:#3c3a3b;font:12px/1.5 \5b8b\4f53;} #msgBox{width:500px;background:#fff;border-radius:5px;margin:10px auto;padding-top:10px;} #msgBox form h2{font-weight:400;font:400 18px/1.5 \5fae\8f6f\96c5\9ed1;} #msgBox form{background:url() repeat-x 0 bottom;padding:0 20px 15px;} #userName,#conBox{color:#777;border:1px solid #d0d0d0;border-radius:6px;background:#fff url(img/inputBG.png) repeat-x;padding:3px 5px;font:14px/1.5 arial;} #userName.active,#conBox.active{border:1px solid #7abb2c;} #userName{height:20px;} #conBox{width:448px;resize:none;height:65px;overflow:auto;} #msgBox form div{position:relative;color:#999;margin-top:10px;} #msgBox img{border-radius:3px;} #face{position:absolute;top:0;left:172px;} #face img{width:30px;height:30px;cursor:pointer;margin-right:6px;opacity:0.5;filter:alpha(opacity=50);} #face img.hover,#face img.current{width:28px;height:28px;border:1px solid #f60;opacity:1;filter:alpha(opacity=100);} #sendBtn{border:0;width:112px;height:30px;cursor:pointer;margin-left:10px;background:url(img/btn.png) no-repeat;} #sendBtn.hover{background-position:0 -30px;} #msgBox form .maxNum{font:26px/30px Georgia, Tahoma, Arial;padding:0 5px;} #msgBox .list{padding:10px;} #msgBox .list h3{position:relative;height:33px;font-size:14px;font-weight:400;background:#e3eaec;border:1px solid #dee4e7;} #msgBox .list h3 span{position:absolute;left:6px;top:6px;background:#fff;line-height:28px;display:inline-block;padding:0 15px;} #msgBox .list ul{overflow:hidden;zoom:1;} #msgBox .list ul li{float:left;clear:both;width:100%;border-bottom:1px dashed #d8d8d8;padding:10px 0;background:#fff;overflow:hidden;} #msgBox .list ul li.hover{background:#f5f5f5;} #msgBox .list .userPic{float:left;width:50px;height:50px;display:inline;margin-left:10px;border:1px solid #ccc;border-radius:3px;} #msgBox .list .content{float:left;width:400px;font-size:14px;margin-left:10px;font-family:arial;word-wrap:break-word;} #msgBox .list .userName{display:inline;padding-right:5px;} #msgBox .list .userName a{color:#2b4a78;} #msgBox .list .msgInfo{display:inline;word-wrap:break-word;} #msgBox .list .times{color:#889db6;font:12px/18px arial;margin-top:5px;overflow:hidden;zoom:1;} #msgBox .list .times span{float:left;} #msgBox .list .times a{float:right;color:#889db6;display:none;} .tr{overflow:hidden;zoom:1;} .tr p{float:right;line-height:30px;} .tr *{float:left;} </style> <script type="text/javascript"> var get = { byId: function(id) { return typeof id === "string" ? document.getElementById(id) : id }, byClass: function(sClass, oParent) { var aClass = []; var reClass = new RegExp("(^| )" + sClass + "( |$)"); var aElem = this.byTagName("*", oParent); for (var i = 0; i < aElem.length; i++) reClass.test(aElem[i].className) && aClass.push(aElem[i]); return aClass }, byTagName: function(elem, obj) { return (obj || document).getElementsByTagName(elem) } }; /*-------------------------- + 事件绑定, 删除 +-------------------------- */ var EventUtil = { addHandler: function (oElement, sEvent, fnHandler) { oElement.addEventListener ? oElement.addEventListener(sEvent, fnHandler, false) : (oElement["_" + sEvent + fnHandler] = fnHandler, oElement[sEvent + fnHandler] = function () {oElement["_" + sEvent + fnHandler]()}, oElement.attachEvent("on" + sEvent, oElement[sEvent + fnHandler])) }, removeHandler: function (oElement, sEvent, fnHandler) { oElement.removeEventListener ? oElement.removeEventListener(sEvent, fnHandler, false) : oElement.detachEvent("on" + sEvent, oElement[sEvent + fnHandler]) }, addLoadHandler: function (fnHandler) { this.addHandler(window, "load", fnHandler) } }; /*-------------------------- + 设置css样式 读取css样式 +-------------------------- */ function css(obj, attr, value) { switch (arguments.length) { case 2: if(typeof arguments[1] == "object") { for (var i in attr) i == "opacity" ? (obj.style["filter"] = "alpha(opacity=" + attr[i] + ")", obj.style[i] = attr[i] / 100) : obj.style[i] = attr[i]; } else { return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, null)[attr] } break; case 3: attr == "opacity" ? (obj.style["filter"] = "alpha(opacity=" + value + ")", obj.style[attr] = value / 100) : obj.style[attr] = value; break; } }; EventUtil.addLoadHandler(function () { var oMsgBox = get.byId("msgBox"); var oUserName = get.byId("userName"); var oConBox = get.byId("conBox"); var oSendBtn = get.byId("sendBtn"); var oMaxNum = get.byClass("maxNum")[0]; var oCountTxt = get.byClass("countTxt")[0]; var oList = get.byClass("list")[0]; var oUl = get.byTagName("ul", oList)[0]; var aLi = get.byTagName("li", oList); var aFtxt = get.byClass("f-text", oMsgBox); var aImg = get.byTagName("img", get.byId("face")); var bSend = false; var timer = null; var oTmp = ""; var i = 0; var maxNum = 140; //禁止表单提交 EventUtil.addHandler(get.byTagName("form", oMsgBox)[0], "submit", function () {return false}); //为广播按钮绑定发送事件 EventUtil.addHandler(oSendBtn, "click", fnSend); //为Ctrl+Enter快捷键绑定发送事件 EventUtil.addHandler(document, "keyup", function(event) { var event = event || window.event; event.ctrlKey && event.keyCode == 13 && fnSend() }); //发送广播函数 function fnSend () { var reg = /^\s*$/g; if(reg.test(oUserName.value)) { alert("\u8bf7\u586b\u5199\u60a8\u7684\u59d3\u540d"); oUserName.focus() } else if(!/^[u4e00-\u9fa5\w]{2,8}$/g.test(oUserName.value)) { alert("\u59d3\u540d\u75312-8\u4f4d\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u6c49\u5b57\u7ec4\u6210\uff01"); oUserName.focus() } else if(reg.test(oConBox.value)) { alert("\u968f\u4fbf\u8bf4\u70b9\u4ec0\u4e48\u5427\uff01"); oConBox.focus() } else if(!bSend) { alert("\u4f60\u8f93\u5165\u7684\u5185\u5bb9\u5df2\u8d85\u51fa\u9650\u5236\uff0c\u8bf7\u68c0\u67e5\uff01"); oConBox.focus() } else { var oLi = document.createElement("li"); var oDate = new Date(); oLi.innerHTML = "<div class=\"userPic\"><img class="current lazy" src="/static/imghwm/default1.png" data-src="face1.gif" src=\"" + get.byClass("current", get.byId("face"))[0].src + "\" alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ></div>\ <div class=\"content\">\ <div class=\"userName\"><a href=\"javascript:;\">" + oUserName.value + "</a>:</div>\ <div class=\"msgInfo\">" + oConBox.value.replace(/<[^>]*>| /ig, "") + "</div>\ <div class=\"times\"><span>" + format(oDate.getMonth() + 1) + "\u6708" + format(oDate.getDate()) + "\u65e5 " + format(oDate.getHours()) + ":" + format(oDate.getMinutes()) + "</span><a class=\"del\" href=\"javascript:;\">\u5220\u9664</a></div>\ </div>"; //插入元素 aLi.length ? oUl.insertBefore(oLi, aLi[0]) : oUl.appendChild(oLi); //重置表单 get.byTagName("form", oMsgBox)[0].reset(); for (i = 0; i < aImg.length; i++) aImg[i].className = ""; aImg[0].className = "current"; //将元素高度保存 var iHeight = oLi.clientHeight - parseFloat(css(oLi, "paddingTop")) - parseFloat(css(oLi, "paddingBottom")); var alpah = count = 0; css(oLi, {"opacity" : "0", "height" : "0"}); timer = setInterval(function () { css(oLi, {"display" : "block", "opacity" : "0", "height" : (count += 8) + "px"}); if (count > iHeight) { clearInterval(timer); css(oLi, "height", iHeight + "px"); timer = setInterval(function () { css(oLi, "opacity", (alpah += 10)); alpah > 100 && (clearInterval(timer), css(oLi, "opacity", 100)) },30) } },30); //调用鼠标划过/离开样式 liHover(); //调用删除函数 delLi() } }; //事件绑定, 判断字符输入 EventUtil.addHandler(oConBox, "keyup", confine); EventUtil.addHandler(oConBox, "focus", confine); EventUtil.addHandler(oConBox, "change", confine); //输入字符限制 function confine () { var iLen = 0; for (i = 0; i < oConBox.value.length; i++) iLen += oConBox.value.charAt(i).charCodeAt() > 255 ? 1 : 0.5; oMaxNum.innerHTML = Math.abs(maxNum - Math.floor(iLen)); maxNum - Math.floor(iLen) >= 0 ? (css(oMaxNum, "color", ""), oCountTxt.innerHTML = "\u8fd8\u80fd\u8f93\u5165", bSend = true) : (css(oMaxNum, "color", "#f60"), oCountTxt.innerHTML = "\u5df2\u8d85\u51fa", bSend = false) } //加载即调用 confine(); //广播按钮鼠标划过样式 EventUtil.addHandler(oSendBtn, "mouseover", function () {this.className = "hover"}); //广播按钮鼠标离开样式 EventUtil.addHandler(oSendBtn, "mouseout", function () {this.className = ""}); //li鼠标划过/离开处理函数 function liHover() { for (i = 0; i < aLi.length; i++) { //li鼠标划过样式 EventUtil.addHandler(aLi[i], "mouseover", function (event) { this.className = "hover"; oTmp = get.byClass("times", this)[0]; var aA = get.byTagName("a", oTmp); if (!aA.length) { var oA = document.createElement("a"); oA.innerHTML = "删除"; oA.className = "del"; oA.href = "javascript:;"; oTmp.appendChild(oA) } else { aA[0].style.display = "block"; } }); //li鼠标离开样式 EventUtil.addHandler(aLi[i], "mouseout", function () { this.className = ""; var oA = get.byTagName("a", get.byClass("times", this)[0])[0]; oA.style.display = "none" }) } } liHover(); //删除功能 function delLi() { var aA = get.byClass("del", oUl); for (i = 0; i < aA.length; i++) { aA[i].onclick = function () { var oParent = this.parentNode.parentNode.parentNode; var alpha = 100; var iHeight = oParent.offsetHeight; timer = setInterval(function () { css(oParent, "opacity", (alpha -= 10)); if (alpha < 0) { clearInterval(timer); timer = setInterval(function () { iHeight -= 10; iHeight < 0 && (iHeight = 0); css(oParent, "height", iHeight + "px"); iHeight == 0 && (clearInterval(timer), oUl.removeChild(oParent)) },30) } },30); this.onclick = null } } } delLi(); //输入框获取焦点时样式 for (i = 0; i < aFtxt.length; i++) { EventUtil.addHandler(aFtxt[i], "focus", function () {this.className = "active"}); EventUtil.addHandler(aFtxt[i], "blur", function () {this.className = ""}) } //格式化时间, 如果为一位数时补0 function format(str) { return str.toString().replace(/^(\d)$/,"0$1") } //头像 for (i = 0; i < aImg.length; i++) { aImg[i].onmouseover = function () { this.className += " hover" }; aImg[i].onmouseout = function () { this.className = this.className.replace(/\s?hover/,"") }; aImg[i].onclick = function () { for (i = 0; i < aImg.length; i++) aImg[i].className = ""; this.className = "current" } } }); </script> </head> <body> <div id="msgBox"> <form> <h2 id="来-说说你在做什么-想什么">来 , 说说你在做什么 , 想什么</h2> <div> <input id="userName" value="" /> <p id="face"><img class="current lazy" src="/static/imghwm/default1.png" data-src="face1.gif" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ><img src="/static/imghwm/default1.png" data-src="face2.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ><img src="/static/imghwm/default1.png" data-src="face1.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ><img src="/static/imghwm/default1.png" data-src="face2.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ></p> </div> <div><input id="conBox" class="f-text"></div> <div class="tr"> <p> <span class="countTxt">还能输入</span><strong class="maxNum">140</strong><span>个字</span> <input id="sendBtn" type="button" value="" title="快捷键 Ctrl+Enter" /> </p> </div> </form> <div class="list"> <h3 id="span-大家在说-span"><span>大家在说</span></h3> <ul> <li> <div class="userPic"><img src="/static/imghwm/default1.png" data-src="face.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ></div> <div class="content"> <div class="userName"><a href="javascript:;">日丶久生情</a>:</div> <div class="msgInfo">新增Ctrl+Enter快捷键发送广播。</div> <div class="times"><span>07月05日 12:20</span><a class="del" href="javascript:;">删除</a></div> </div> </li> <li> <div class="userPic"><img src="/static/imghwm/default1.png" data-src="face.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ></div> <div class="content"> <div class="userName"><a href="javascript:;">日丶久生情</a>:</div> <div class="msgInfo">新增选择头像功能。</div> <div class="times"><span>07月05日 12:08</span><a class="del" href="javascript:;">删除</a></div> </div> </li> <li> <div class="userPic"><img src="/static/imghwm/default1.png" data-src="face.gif" class="lazy" / alt="Js는 Refresh_javascript 기술 없이 콘텐츠 삭제를 실현합니다." ></div> <div class="content"> <div class="userName"><a href="javascript:;">日丶久生情</a>:</div> <div class="msgInfo">增加了记录广播时间的功能。</div> <div class="times"><span>07月04日 16:55</span><a class="del" href="javascript:;">删除</a></div> </div> </li> </ul> </div> </div> </body> </html>
以上所述就是本文给大家分享的全部内容了,希望大家能够喜欢。

JavaScript는 웹 페이지의 상호 작용과 역학을 향상시키기 때문에 현대 웹 사이트의 핵심입니다. 1) 페이지를 새로 고치지 않고 콘텐츠를 변경할 수 있습니다. 2) Domapi를 통해 웹 페이지 조작, 3) 애니메이션 및 드래그 앤 드롭과 같은 복잡한 대화식 효과를 지원합니다. 4) 성능 및 모범 사례를 최적화하여 사용자 경험을 향상시킵니다.

C 및 JavaScript는 WebAssembly를 통한 상호 운용성을 달성합니다. 1) C 코드는 WebAssembly 모듈로 컴파일되어 컴퓨팅 전력을 향상시키기 위해 JavaScript 환경에 도입됩니다. 2) 게임 개발에서 C는 물리 엔진 및 그래픽 렌더링을 처리하며 JavaScript는 게임 로직 및 사용자 인터페이스를 담당합니다.

JavaScript는 웹 사이트, 모바일 응용 프로그램, 데스크탑 응용 프로그램 및 서버 측 프로그래밍에서 널리 사용됩니다. 1) 웹 사이트 개발에서 JavaScript는 HTML 및 CSS와 함께 DOM을 운영하여 동적 효과를 달성하고 jQuery 및 React와 같은 프레임 워크를 지원합니다. 2) 반응 및 이온 성을 통해 JavaScript는 크로스 플랫폼 모바일 애플리케이션을 개발하는 데 사용됩니다. 3) 전자 프레임 워크를 사용하면 JavaScript가 데스크탑 애플리케이션을 구축 할 수 있습니다. 4) node.js는 JavaScript가 서버 측에서 실행되도록하고 동시 요청이 높은 높은 요청을 지원합니다.

Python은 데이터 과학 및 자동화에 더 적합한 반면 JavaScript는 프론트 엔드 및 풀 스택 개발에 더 적합합니다. 1. Python은 데이터 처리 및 모델링을 위해 Numpy 및 Pandas와 같은 라이브러리를 사용하여 데이터 과학 및 기계 학습에서 잘 수행됩니다. 2. 파이썬은 간결하고 자동화 및 스크립팅이 효율적입니다. 3. JavaScript는 프론트 엔드 개발에 없어서는 안될 것이며 동적 웹 페이지 및 단일 페이지 응용 프로그램을 구축하는 데 사용됩니다. 4. JavaScript는 Node.js를 통해 백엔드 개발에 역할을하며 전체 스택 개발을 지원합니다.

C와 C는 주로 통역사와 JIT 컴파일러를 구현하는 데 사용되는 JavaScript 엔진에서 중요한 역할을합니다. 1) C는 JavaScript 소스 코드를 구문 분석하고 추상 구문 트리를 생성하는 데 사용됩니다. 2) C는 바이트 코드 생성 및 실행을 담당합니다. 3) C는 JIT 컴파일러를 구현하고 런타임에 핫스팟 코드를 최적화하고 컴파일하며 JavaScript의 실행 효율을 크게 향상시킵니다.

실제 세계에서 JavaScript의 응용 프로그램에는 프론트 엔드 및 백엔드 개발이 포함됩니다. 1) DOM 운영 및 이벤트 처리와 관련된 TODO 목록 응용 프로그램을 구축하여 프론트 엔드 애플리케이션을 표시합니다. 2) Node.js를 통해 RESTFULAPI를 구축하고 Express를 통해 백엔드 응용 프로그램을 시연하십시오.

웹 개발에서 JavaScript의 주요 용도에는 클라이언트 상호 작용, 양식 검증 및 비동기 통신이 포함됩니다. 1) DOM 운영을 통한 동적 컨텐츠 업데이트 및 사용자 상호 작용; 2) 사용자가 사용자 경험을 향상시키기 위해 데이터를 제출하기 전에 클라이언트 확인이 수행됩니다. 3) 서버와의 진실한 통신은 Ajax 기술을 통해 달성됩니다.

보다 효율적인 코드를 작성하고 성능 병목 현상 및 최적화 전략을 이해하는 데 도움이되기 때문에 JavaScript 엔진이 내부적으로 작동하는 방식을 이해하는 것은 개발자에게 중요합니다. 1) 엔진의 워크 플로에는 구문 분석, 컴파일 및 실행; 2) 실행 프로세스 중에 엔진은 인라인 캐시 및 숨겨진 클래스와 같은 동적 최적화를 수행합니다. 3) 모범 사례에는 글로벌 변수를 피하고 루프 최적화, Const 및 Lets 사용 및 과도한 폐쇄 사용을 피하는 것이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

맨티스BT
Mantis는 제품 결함 추적을 돕기 위해 설계된 배포하기 쉬운 웹 기반 결함 추적 도구입니다. PHP, MySQL 및 웹 서버가 필요합니다. 데모 및 호스팅 서비스를 확인해 보세요.

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)
