请帮忙。jquery addClass()不能与event.target配合使用
为什么jquery addClass()
不能与event.target
一起使用? 我已经做了一个代码,它应该点击目标时添加类,但它不起作用,它说,e.target.addClass
是不是一个函数。
CODE:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Class Test</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<style>
.big {
font-size: 5em;
}
.small {
font-size: 1em;
}
</style>
</head>
<body>
<p>This is the text</p>
<script>
$(function() {
$("p").click(function(e) {
$("a").removeClass("big").addClass("small");
$("this").addClass("big"); //This doesn't work
e.target.addClass("big"); //nor this one
});
});
</script>
</body>
</html>
哇。有用!这是为什么? – qtgye
@ user3540736我已经在我的答案中给出了一些解释.. :) –
现在对我来说很清楚。非常感谢! :) – qtgye