我想更改事件附加到的元素。在下面的示例中,我尝试将边框从 2px 增加到 10 px,但没有成功。
完整的最小示例(查找 FAILS 行):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Example</title>
<style>P { margin-bottom: 40%; }</style>
</head>
<body>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<p>Paragraph 3</p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$('p').each(function (i) {
$(this).css('border', '2px solid');
$(window).scroll(function (event) {
console.log('scroll triggered, but nothing happens!');
event.target.css('border', '10px solid'); // FAILS with TypeError: event.target.css is not a function
});
})
</script>
</body>
</html>