【发布时间】:2014-04-22 05:32:17
【问题描述】:
请帮忙。
为什么 jquery addClass() 不能与 event.target 一起使用?
我编写了一个代码,它应该在单击时在目标上添加类,但它不起作用,它说,e.target.addClass 不是一个函数。
代码:
<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>
【问题讨论】:
标签: jquery events target addclass