<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>attr()函数-脚本之家</title>
<style type="text/css">
.font{
font-size:18px;
color:yellow
}
.bg{
background:#336;
}
.second{
color:green
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
alert($("div").attr("class"));
})
})
</script>
</head>
<body>
<div class="font bg">我是第一个div</div>
<div class="second">我是第二个div</div>
<button id="btn">点击查看效果</button>
</body>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>attr()函数-脚本之家</title>
<style type="text/css">
.font{
font-size:18px;
color:yellow
}
.bg{
background:#336;
}
.second{
color:green
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
alert($("div").attr("class"));
})
})
</script>
</head>
<body>
<div class="font bg">我是第一个div</div>
<div class="second">我是第二个div</div>
<button id="btn">点击查看效果</button>
</body>
</html>
----------------简单语法规则---------------------
<button οnclick="a()">点击这里</button>
<p id="demo"></p>
<p id="demo2"></p>
<script>
var b=0;
function a(){
b++;
document.getElementById("demo").innerHTML=b;
if(b%2==0){
document.getElementById("demo2").innerHTML=b+"偶数";
}
}
</script>