document ready

<html>
<head>
	<title></title>
	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
	<style type="text/css">
		.emphasis {color: green}
	</style>	

	<script type="text/javascript">

		//两种写法都可以
		$(function() {
			$('li:first-child').addClass('emphasis');
		})

		$(document).ready(function() {
			$('li:first-child').addClass('emphasis');
		});
		
	</script>
</head>
<body>
<ul>
	<li>hello</li>
	<li>hello 2</li>
	<li>hello 3</li>
</ul>

</body>
</html>

你可能感兴趣的:(document)