Selector Selector / #id
html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
alert($("#txtUserName").attr("value"));
}
);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="txtUserName" value="Quoc Hung" type="text" />
</div>
</form>
</body>
</html>
Selector / Element
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("div").css("border", "3px solid yellow").css("width", "200px") ;
}
);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="txtUserName" value="Quoc Hung" type="text" />
</div>
</form>
</body>
</html>
Selector / .Class
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".test").css("border", "4px solid violet").css("width", "200px");
}
);
</script>
</head>
<body>
<form id="form1" runat="server" class="test">
<div>
<input id="txtUserName" value="Quoc Hung" type="text" />
</div>
</form>
</body>
</html>
Selector *
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("*").css("border", "1px solid blue");
});
</script>
<style>
div, span, p
{
width: 100px;
height: 60px;
float: left;
padding: 10px;
margin: 10px;
background-color: #EEEEEE;
}
</style>
</head>
<body>
<div>
DIV</div>
<span>SPAN</span>
<p>
P
<button>
Button</button></p>
</body>
</html>
Selector / multi
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("div,span").css("border", "1px solid blue");
});
</script>
<style>
div, span, p
{
width: 100px;
height: 60px;
float: left;
padding: 10px;
margin: 10px;
background-color: #EEEEEE;
}
</style>
</head>
<body>
<div>
DIV</div>
<span>SPAN</span>
<p>
P
<button>
Button</button></p>
</body>
</html>
Selector / type
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var inputButton = $(":button").css({ background: "yellow", border: "3px red solid" });
alert(inputButton.attr("value"));
});
</script>
</head>
<body>
<input type="button" id="btnOK" value="OK" />
</body>
</html>
Selector / [attribute=value]
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var inputButton = $("input[value=Cancel]").css({ background: "yellow", border: "3px red solid" });
alert(inputButton.attr("value"));
});
</script>
</head>
<body>
<input type="button" id="btnOK" value="OK" />
<input type="button" id="btnCancel" value="Cancel" />
</body>
</html>
|
No comments:
Post a Comment