在页面中,增加一个
元素标记,用户单击该元素时,变换其字体和背景颜色,再次单击时,恢复其初始的字体和背景色。
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQuery事件的链式写法</title>
<script type="text/javascript" src="jquery-2.1.4.js"></script>
<style type="text/css" >
.iframe{ border:soild 1px #888; font-size:13px;}
.defcol{ padding:8px; background-color:#eee;}
.curcol{ padding:8px; background-color:#ccc; color:#fff }
</style>
<script type="text/javascript">
$(function(){
$(".defcol").click(function(){
$(this).toggleClass("curcol");
})
})
</script>
</head>
<body>
<div class="iframe">
<div class="defcol">标题</div>
</div>
</body>
</html>