jquery files need to be referenced with jquery (jquery at the top of the page referencing multiple JS files)
<script src="jquery-1.11.2.min.js"></script>
The "$" symbol represents the selector
<script type="text/javascript">
$(document).ready(
function
(e) {
function是匿名函数,e是形参
});
</script>
JS中的找元素,DOM对象
var a = document.getElementById(""); 根据id找
alert();
var a = document.getElementsByClassName(""); 根据class名找
alert();
var a = document.getElementsByTagName(""); 根据标签找
var a = document.getElementsByName(""); 根据name找Jquery:var A = $ ("#aa"); Search by ID (#)
var
a = $(
".bb"
);
根据class名找(.)
var
a = $(
"div"
);
根据标签名找(标签名称)
var
a = $(
"[name=‘cc‘]"
);
根据属性找(属性名称)jquery Operation Properties:
a.attr("","");(设置)
alert(a.attr(""));(获取)
a.removeAttr("");(移除)jquery event: Single Add:
<input type=
"button"
value=
"测试"
id=
"btn"
/>
$(
"#btn"
).click(
function
(){
alert(
"czx"
);
}); 会显示czxMultiple additions:
<input type=
"button"
value=
"测试1"
class
=
"btn"
/>
<input type=
"button"
value=
"测试2"
class
=
"btn"
/>
<input type=
"button"
value=
"测试3"
class
=
"btn"
/>
$(
".btn"
).click(
function
(){
//alert("czx111");
alert($(this).val());
}); 通过class名找到要修改的元素,谁触发的它,this就代表谁Hang Event:
<input type=
"button"
value=
"挂事件"
id=
"gua"
/>
<input type=
"button"
value=
"测试事件"
id=
"ceshi"
/>
<input type=
"button"
value=
"移除事件"
id=
"yichu"
/>
Click the test Events button to hang an event
$ ("#gua"). Click (function () {(bind bind method for hanging Events)
$ ("#ceshi"). bind ("click", function () {
Alert ("hang up the event");
});
});
Click the Test Event button to remove the Click event
$ ("#yichu"). Click (function () {(unbind Method (the event name to UNBIND))
$ ("#ceshi"). Unbind ("click");
})
});
1.3 jquery Basics