jquery----->helloworld

<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())

原文地址:https://www.cnblogs.com/bulrush/p/5793623.html