码迷,mamicode.com
首页 > Web开发 > 详细

jQuery操作得到DOM元素

时间:2015-07-17 16:18:21      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:jquery操作得到dom元素

         jQueryDOM操作方面提供了一些函数及其使用方法,这里就对DOM元素的包装简单说明一下,如何使用会了,对其他方法也能灵活的使用。下面是一个小例子及其效果图。

代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>演示jquery操作得到的元素</title>
    <%--引入jquery文件--%>
    <script  type ="text/javascript" src ="jquery-2.1.4.js"></script>
    <script  type ="text/javascript">
        $(document).ready(function () {
            //触发onclick事件
            $("#testbutton").click(
                function () {
                    //使用class为test的元素包裹给定元素
                    $("p").wrap($(".test"));
                }
                );
        });
    </script>
    <%--基本样式设定--%>
    <style type ="text/css">
        .test {
        color :white ;
        background-color :#ffd800;
        }
        .wrap {
        background-color :green ;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        
    <div id="content">
        <button id="testbutton">测试</button>
        <br /><br />
        <div class ="test"></div>
        <p id ="first">第一段文字,id为first</p>
        <p id ="second">第二段文字,id为second</p>
        <p id ="third">第三段文字,id为third</p>
    </div>
    </form>
</body>
</html>
  对于jQuery的使用自己要多多实践,这样才能对它了如指掌啊~

版权声明:本文为博主原创文章,未经博主允许不得转载。

jQuery操作得到DOM元素

标签:jquery操作得到dom元素

原文地址:http://blog.csdn.net/xfz0330/article/details/46927199

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!