廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:
<html><head><meta charset="utf-8"><title></title><style>ul {list-style: none;}li {line-height: 25px;margin-top: 3px;}li:hover {background-color: #ddd;}li.hover {background-color: #fc0;}</style><script src="./jquery-2.2.4.min.js"></script><script type="text/javascript">$(function() {//獲取每一個li節點并設置點擊事件$("li").click(function() {//當點擊某一個節點的時候,增加類名為hover$(this).toggleClass("hover");});//獲取刪除按鈕并設置點擊事件$("button").click(function() {//將類名是hover的節點刪除$("li.hover").remove();});});</script></head><body><h2 id="hid">jQuery實例--節點刪除</h2><ul><li>asdfasdfasfd</li><li>asdfasdfasfd</li><li>asdfasdfasfd</li><li>asdfasdfasfd</li><li>asdfasdfasfd</li><li>asdfasdfasfd</li></ul><button>刪除</button></body></html>
以上所述是小編給大家介紹的jQuery實現刪除li節點的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答