jQuery对节点进行操作

来源:互联网 发布:装潢艺术设计软件技能 编辑:程序博客网 时间:2024/06/10 04:49
    <title></title>


    <script src="jquery-1.9.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {


            //如果clone()方法的参数为true,则此元素的事件也会被复制,如果为空(默认为false),则事件不会被复制
            $('#img1').click(function () {
                $(this).clone(true).appendTo('div');
            })


            $('#img1').mouseout(function () {
                alert(1);
            })


            $('#Button1').click(function () {
                //After和Before是将一个新的节点插入到已有节点的后面或者前面
                $('p').after('<p>After Hello World</p>');
            })
            $('#Button2').click(function () {
                $('p').before('<p>Before Hello World</p>');
            })
            $('#Button3').click(function () {
                //insertAfter和insertBefore是对两个已有的节点进行操作。
                $('p:first').insertAfter($('p:last'));
            })


            $('input').click(function () {
               alert($('input').length);
                $('body').css('background-color', $(this).attr('value'));
            })
        })
    
    </script>


</head>
<body>
         <img src="images/1.jpg" id="img1" />
             <div></div><br />
      <p>Hello World</p>
    <input id="Button1" type="button" value="After" />
    <input id="Button2" type="button" value="Befor" />
    <input id="Button3" type="button" value="Revert" />
    <input id="Button4" type="button" value="yellow" />
    <select id="Select1" multiple="multiple">
        <option value="red">sss</option>
    </select>
        <div></div>
</body>
</html>