jQuery 中的事件屬性是什麼?
jQuery 事件具有屬性,例如對於 keyup 和 keydown 事件,如果按下了 Ctrl 鍵,則在事件建立時新增時間戳等。
以下是可用的一些事件屬性/屬性
| 序號 | 屬性和說明 |
|---|---|
| 1 | altKey 在觸發事件時如果按下了 Alt 鍵,則設定為 true,如果沒有按下則設定為 false。大多數 Mac 鍵盤上的 Alt 鍵標記為 Option。 |
| 2 | ctrlKey 在觸發事件時如果按下了 Ctrl 鍵,則設定為 true,如果沒有按下則設定為 false。 |
| 3 | data 在建立處理程式時作為第二個引數傳遞的值(如果有)。 |
| 4 | pageX 對於滑鼠事件,指定事件與頁面原點之間的水平座標。 |
| 5 | pageY 對於滑鼠事件,指定事件與頁面原點之間的垂直座標。 |
示例
你可以嘗試執行以下程式碼以瞭解如何使用 jQuery 事件屬性
<html>
<head>
<title>jQuery Attributes</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$('div').bind('click', function( event ){
alert('Event type is ' + event.type);
alert('pageX : ' + event.pageX);
alert('pageY : ' + event.pageY);
alert('Target : ' + event.target.innerHTML);
});
});
</script>
<style>
.div {
margin:10px;
padding:12px;
border:2px solid #666;
width:60px;
}
</style>
</head>
<body>
<p>Click on any square below to see the result:</p>
<div class = "div" style = "background-color:blue;">ONE</div>
<div class = "div" style = "background-color:green;">TWO</div>
<div class = "div" style = "background-color:red;">THREE</div>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP