HTML KeyboardEvent which 屬性


HTML KeyboardEvent which 屬性返回在 HTML 文件中觸發 onkeypress 事件、onkeydown 事件或 onkeyup 事件的鍵的 Unicode 字元程式碼。

語法

以下是語法 -

event.which

讓我們看一個 HTML KeyboardEvent which 屬性的示例 -

示例

 演示

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      text-align: center;
   }
   input {
      border: 2px solid #fff;
      padding: 8px;
      background: transparent;
      width: 310px;
      border-radius: 20px;
      outline: none;
   }
   ::placeholder {
      color: #000;
   }
   .show {
      font-size: 1.2rem;
      color: #fff;
   }
</style>
<body>
<h1>HTML KeyboardEvent which Property Demo</h1>
<input type="text" placeholder="Enter your message" onkeypress="display(event)">
<div class="show">
<p>The above message in Unicode character is:</p>
</div>
<script>
   function display(event) {
      document.querySelector(".show").innerHTML += "<p>" + event.which + "</p>";
   }
</script>
</body>
</html>

輸出

現在開始在文字欄位中鍵入您的訊息,然後在 Unicode 字元下方看到相同的訊息 -

更新於:26-Sep-2019

53 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.