$("a").click(function() {
$("#colorMe").attr("class", $(this).attr("id"));
event.preventDefault();
});这段代码中"class"是什么意思啊、才学、请教啊
$("#colorMe").attr("class", $(this).attr("id"));
event.preventDefault();
});这段代码中"class"是什么意思啊、才学、请教啊
这样用也可以用来设置一个样式
<div class=""></div>
就是这里的class。
这个我知道、这是源码:
jQuery
$(document).ready(function() {
$("a").hover(function() {
$(this).css({
"color": $(this).attr("id"),
"background-color": "silver"
});
});
$("a").mouseout(function() {
$(this).css({
"color": "white",
"background-color": "gray"
});
});
$("a").click(function() {
$("#colorMe").attr("class", $(this).attr("id"));
event.preventDefault();
});
});
html:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to jQuery #4!</title>
<link rel="stylesheet" href="script04.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script src="script04.js"></script>
</head>
<body>
<h1 id="colorMe">Pick a color</h1>
<p>
<a id="red">Red</a>
<a id="green">Green</a>
<a id="blue">Blue</a>
</p>
</body>
</html>
那几个a标签的id刚好是颜色值,在你的样式表script04.css中应该也定义有.red{};.green{};.blue{}等样式应用。我在1楼告诉你说是设置样式,你说你知道的呀