我是一名jQuery初学者,希望实现以下目标 - 无论何时点击页面的任何元素,我都希望其中的文本颜色改为红色。这是我的,但它不起作用。令人惊讶的是,警报声明也没有打印任何内容但它确实执行,因为我用另一个警报语句测试了它。谢谢。点击jQuery改变颜色
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>Cow</div>
<div>Cat</div>
<p>paragraph</p>
<p>coconut</p>
<script type="text/javascript" src="../Scripts/jquery-2.0.3.js"></script>
<script type="text/javascript">
$(this).click(function() {
var v = $(this).text();
alert(v); // this prints nothing !!!!
$(this).css("color", "red");
});
</script>
</body>
而且你能指望什么'$(这)'是? –
页面的任何元素 - p,div,a等 – VVV