我想更改附加事件的元素。在下面的例子中,我嘗試將border從2px增加到10px,但沒有成功。發生事件時更改元素
完整的小例子(查找失敗行):
<?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>
正是你試圖改變邊界是什麼?整個窗戶? –
@ShadowWizard:來自'2px'的每個''p'我最初在發生滾動時使用jQuery設置爲'10px'。編輯:我看到我的錯誤 – Deleted