这是在 jQuery 中实现此目的的一种方法。如果您愿意,您可以选择向正文添加一个类,但请记住先删除其他类。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#colour').change(function(){
$('body').css('background',$(this).val());
});
});
</script>
</head>
<body>
<select id="colour">
<option value="">Please Select
<option value="#00F">Blue</option>
<option value="#F00">Red</option>
<option value="#0F0">Green</option>
</select>
</body>
</html>
或通过课程:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#colour').change(function(){
$('body').removeClass('blue red green').addClass($(this).val());
});
});
</script>
<style type="text/css">
.blue { background: #00F; }
.green { background: #0F0; }
.red { background: #F00; }
</style>
</head>
<body>
<select id="colour">
<option value="">Please Select
<option value="blue">Blue</option>
<option value="red">Red</option>
<option value="green">Green</option>
</select>
</body>
</html>