jquery each
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function Change() {
$("img").each(function (i) {
this.src = "test" + i + ".jpg";
});
}
function Change2() {
$("#button").click(function () {
$("div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "yellow");
if ($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
return false;
}
});
});
}
function Change3() {
$("#test3").click(function () {
$("#test div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "red");
});
});
}
function onloadchange() {
Change2();
Change3();
}
</script>
</head>
<body onload="onloadchange()">
<form id="form1" runat="server">
<img/><img/>
<input type="button" onclick="Change()" value="测试"/>
<input type="button" id="button" value="测试2"/>
<input type="button" id="test3" value="测试3" />
<span></span>
<div>div0</div>
<div>div1</div>
<div>div2</div>
<div>div3</div>
<div id="stop">Stop here</div>
<div>div5</div>
<div>div6</div>
<div>div7</div>
<div id="test">test
<div>testchild</div>
<div>testchild</div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function Change() {
$("img").each(function (i) {
this.src = "test" + i + ".jpg";
});
}
function Change2() {
$("#button").click(function () {
$("div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "yellow");
if ($(this).is("#stop")) {
$("span").text("Stopped at div index #" + index);
return false;
}
});
});
}
function Change3() {
$("#test3").click(function () {
$("#test div").each(function (index, domEle) {
// domEle == this
$(domEle).css("backgroundColor", "red");
});
});
}
function onloadchange() {
Change2();
Change3();
}
</script>
</head>
<body onload="onloadchange()">
<form id="form1" runat="server">
<img/><img/>
<input type="button" onclick="Change()" value="测试"/>
<input type="button" id="button" value="测试2"/>
<input type="button" id="test3" value="测试3" />
<span></span>
<div>div0</div>
<div>div1</div>
<div>div2</div>
<div>div3</div>
<div id="stop">Stop here</div>
<div>div5</div>
<div>div6</div>
<div>div7</div>
<div id="test">test
<div>testchild</div>
<div>testchild</div>
</div>
</form>
</body>
</html>