<!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>
<title></title>
<style type="text/css">
body
{
background-image:url(image1/9.jpg);
}
p
{
background-color:#eee;
font-size:30px;
}
.pclass
{
font-weight:bold;
font-family:楷体,Arial;
}
.pcolorclass
{
color:Red;
}
.psanclass
{
background-color:Blue;
}
.backpic
{
background-image:url(image1/8.jpg);
}
</style>
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btnclass').click(function () {
$('p').css('background-color', 'blue');
})
$('#btnAdd').click(function () {
$('p').addClass('pclass pcolorclass psanclass'); //添加样式,字体都按新的样式改变,可以添加多个样式,以空格区别
})
$('#btnremove').click(function () {
//$('p').removeClass(''); //删除样式,添加的新样式都删掉,一开始设置的样式删不了
//$('p').removeClass('psanclass');可以指定删除的样式
})
$('#btntihuan').click(function () {
$('p').toggleClass('pcolorclass'); //添加样式,字体都按新的样式改变,可以添加多个样式,以空格区别
})
//----------------------------------------------------------------
//$('#btnUpdate').click(function () {
//var numb = Math.random();
//var numb1 = Math.floor(numb * 15 + 1);
//$('img').attr('src', 'image1/' + numb1 + '.jpg'); //随机改图片
//})
//$('#btntihuanpic').click(function () {
//$('body').toggleClass('backpic');
//})
$('#btntihuanpic').click(function () {
var numb = Math.random();
var numb1 = Math.floor(numb * 15 + 1);
$('body').css('background-image', 'url(image1/' + numb1 + '.jpg)');
})
})
</script>
</head>
<body>
<p class="pclass">Hello World:你好!</p>
<input type="button" id="btnclass" value="设置样式" />
<input type="button" id="btnAdd" value="添加样式" />
<input type="button" id="btnremove" value="删除样式" />
<input type="button" id="btntihuan" value="替换样式" />
<input type="button" id="btntihuanpic" value="替换背景图片" />
</body>
</html>