首先 需要插入jquery
<script src="jquery-1.11.2.min.js"></script>
这句代码是放在最开头的
$符号代表选择器
$(document).ready(function(e)
这句是代表页面加载完成之后执行,如果jquery代码写在了页面最低端,则不需要此句
找元素,Jquery对象 var b = $("#aa"); //根据ID找
var b = $(".aa"); //根据class找 alert(b[1]); //找到的是DOM对象 alert(b.eq(1)); //找到的是Jquery对象
var b = $("div"); //根据标签名找
var b = $("[id='aa']"); //根据属性找
jquery操作内容
非表单元素 b.html(); //操作元素里面的HTML代码 b.text(); //操作元素里面的文本 表单元素 b.val("hello");
操作属性
//设置属性 //b.attr("bs","test"); //获取属性 //alert(b.attr("aa")); //移除属性 //b.removeAttr("aa"); //b.prop("checked",false);
操作样式
//操作样式,可以获取内嵌的样式 //b.css("background-color","red"); //alert(b.css("width")); //alert(b.css("background-color"));