Home > Web Front-end > JS Tutorial > body text

Jquery动态添加及删除页面节点元素示例代码_jquery

WBOY
Release: 2016-05-16 16:44:22
Original
1089 people have browsed it

通常我们会遇到选中某个条件,然后添加,累计多个后,再进行执行。

废话不多说,直接上代码!

复制代码 代码如下:





Jquery动态添加及删除页面节点


<script> <BR>$(function(){//页面加载完毕后执行 <BR>$("input").click(function(){//添加操作 <BR>var getval=$("select").val();//获取当前选中的select值 <BR>$("p").before('<li>'+getval+'<span>X');//在p标签前加入所要生成的代码 <BR>}); <BR>}); <BR>$("span").live("click",function(){//通过 live() 方法附加的事件处理程序适用于匹配选择器的当前及未来的元素(比如由脚本创建的新元素) <BR>$(this).parent().remove();//移除当前点击元素的父元素 <BR>}); <BR></script>












Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!