您好,欢迎访问一九零五行业门户网

jQuery动态操作div步骤详解

这次给大家带来jquery动态操作div步骤详解,jquery动态操作div步的注意事项有哪些,下面就是实战案例,一起来看一下。
代码实例如下:
<!doctype html> <html> <head> <meta charset="utf-8"> <style type="text/css"> #father {  width:150px;  height:150px;  background-color:red; } #father p {  width:50px;  height:50px;  background-color:green;  font-size:12px; } </style> <script type="text/javascript" src="/jquery/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){  $(#father).prepend(<p>脚本之家欢迎您</p>); }) </script> </head> <body> <p id="father"></p> </body> </html>
以上代码可以在父p中添加一个p,下面再介绍一下如何删除一个p,下面只给出核心代码:
$(document).ready(function(){  $(#father).prepend(<p>脚本之家欢迎您</p>);  $(p).remove(#father p); })
以上代码可以移除添加的p。
示例二:
<!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=utf-8" />  <title>add and close p</title>  <script type="text/javascript教程" >  $(document).ready(function(){      bindlistener(); }) function addimg(){      $(#mp).append('<p class="iptp" ><input type="file" name="img[]" class="ipt" /><a href="#" name="rmlink">x</a></p>');           // 为新元素节点添加事件侦听器     bindlistener(); } // 用来绑定事件(使用unbind避免重复绑定) function bindlistener(){     $(a[name=rmlink]).unbind().click(function(){         $(this).parent().remove();      }) } </script>   </head>   <body>  <form action="" method="post" enctype="multipart/form-data">   <label>请选择上传的图片</label>    <a href="javascript:addimg()" id="addimg">增加图片</a>    <p class="mp" id="mp">      <p class="iptp" ><input type="file" name="img[]" class="ipt" /><a href="#" name="rmlink">x</a></p>     </p>    <input type="submit" name="submit" value="上传图片" />   </form>   </body>   </html>
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery解析xml文件详解
jquery动态加载js脚本文件实现方法
以上就是jquery动态操作div步骤详解的详细内容。
其它类似信息

推荐信息