首页 > Web开发 > 详细

jquery----->helloworld

时间:2016-08-21 22:31:44      阅读:134      评论:0      收藏:0      [点我收藏+]
<html>
<head>
<title>first jquery</title>

<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
    
    //$(function(){}) 相当于 window.onload, 代码卸载 {} 之间
    $(function(){
        //1. 选取 button: $("button")
        //2. 为 button 添加 onclick 响应函数: $("button").click(function(){})
        //代码编写在 function 的 {} 中. 
        $("button").click(function(){
            //3. 弹出 helloworld
            alert("helloworld");
        });
    })

</script>
</head>
<body>
    <button id="button">ClickMe</button>
</body>
</html>

jQuery对象就是通过jQuery($())包装DOM对象后产生的对象。

var $variable=jQuery对象

var variable=DOM对象

由于jQuery对象是一个数组对象。所以可以根据下标转换成DOM对象。

alert($btn[0].firstChild.nodeValue);

由DOM对象转换成jQuery对象。使用$()包装

alert($(btn).text())

jquery----->helloworld

原文:http://www.cnblogs.com/bulrush/p/5793623.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!