HTML DOM UiEvent detail 屬性返回與連續觸發的點擊對應的數字。
NOTE− 如果ondblclick 事件被觸發,返回值為‘2’,如果onmouseover 或onmouseout 事件被觸發,則總是‘0’。
用法
以下是語法 -
返回連續觸發的點擊次數 -
event.detail
讓我們看一個例子Event detail屬性 -
示例
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM UiEvent detail</title>
<style>
form {
width:70%;
margin:0 auto;
text-align:center;
}
* {
padding:2px;
margin:5px;
}
input[type="button"] {
border-radius:10px;
}
#playArea {
display:inline-block;
border-radius:50%;
background-color:#DC3545;
width:50px;
height:50px;
border:3px solid #AC3509;
}
#clickOn {
border:3px solid #F0FF33;
margin:15px auto;
border-radius:50%;
background-color:#FFF933;
width:10px;
height:10px;
}
h2 {
display:inline-block;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>HTML-DOM-UiEvent-detail</legend>
<h2 id="highScore">High Score:0</h2>
<h2 id="currScore">Current Score:0</h2><br>
<div id="playArea"><div onclick="getHighScore(event)" id="clickOn"></div></div><br>
</fieldset>
</form>
<script>
var clickOn = document.getElementById("clickOn");
var playDisplay = document.getElementById("playArea");
var highScore = document.getElementById("highScore");
var currScore = document.getElementById("currScore");
var high = 0, score = 0;
function getHighScore(event) {
var score = event.detail;
currScore.textContent = 'Current Score:'+score;
if(score > high){
highScore.textContent = 'High Score:'+score;
high = score;
}
}
</script>
</body>
</html>
輸出
單擊黃色 div 元素之前 -
連續點擊黃色 div 元素後 -
連續點擊黃色 div 元素但比上一次少後 -
相關用法
- HTML DOM URL searchParams屬性用法及代碼示例
- HTML DOM Underline用法及代碼示例
- HTML DOM Ul用法及代碼示例
- HTML DOM Style overflowY屬性用法及代碼示例
- HTML DOM Document hidden屬性用法及代碼示例
- HTML DOM IFrame用法及代碼示例
- HTML DOM Textarea cols屬性用法及代碼示例
- HTML DOM Style pageBreakAfter屬性用法及代碼示例
- HTML DOM Base href屬性用法及代碼示例
- HTML DOM Pre用法及代碼示例
- HTML DOM Input Month用法及代碼示例
- HTML DOM Video canPlayType()用法及代碼示例
- HTML DOM Range deleteContents()用法及代碼示例
- HTML DOM console.dirxml()用法及代碼示例
- HTML DOM Style transition屬性用法及代碼示例
- HTML DOM Video volume屬性用法及代碼示例
- HTML DOM Input Range用法及代碼示例
- HTML DOM Style outlineOffset屬性用法及代碼示例
- HTML DOM Storage setItem()用法及代碼示例
- HTML DOM TableHeader用法及代碼示例
注:本文由純淨天空篩選整理自AmitDiwan大神的英文原創作品 HTML DOM UiEvent detail Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。