JS類比鍵盤打字效果的方法_javascript技巧

來源:互聯網
上載者:User

本文執行個體講述了JS類比鍵盤打字效果的方法。分享給大家供大家參考。具體如下:

這裡使用JS類比實現軟鍵盤及打字效果,點擊軟鍵盤年的字母鍵,文字框中即可顯示文字,像是鍵盤打字的效果,美工不太好,沒怎麼美化,CSS高手可美化一下按鈕,看上去還挺不錯吧,我覺得。

先來看看運行效果圖:

具體代碼如下:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>類比鍵盤打字</title></head><body><script Language="Javascript">function a(){var text=document.form.text.valuedocument.form.text.value=text + "A";}function b(){var text=document.form.text.valuedocument.form.text.value=text + "B";}function c(){var text=document.form.text.valuedocument.form.text.value=text + "C";}function d(){var text=document.form.text.valuedocument.form.text.value=text + "D";}function e(){var text=document.form.text.valuedocument.form.text.value=text + "E";}function f(){var text=document.form.text.valuedocument.form.text.value=text + "F";}function g(){var text=document.form.text.valuedocument.form.text.value=text + "G";}function h(){var text=document.form.text.valuedocument.form.text.value=text + "H";}function i(){var text=document.form.text.valuedocument.form.text.value=text + "I";}function j(){var text=document.form.text.valuedocument.form.text.value=text + "J";}function k(){var text=document.form.text.valuedocument.form.text.value=text + "K";}function l(){var text=document.form.text.valuedocument.form.text.value=text + "L";}function m(){var text=document.form.text.valuedocument.form.text.value=text + "M";}function n(){var text=document.form.text.valuedocument.form.text.value=text + "N";}function o(){var text=document.form.text.valuedocument.form.text.value=text + "O";}function p(){var text=document.form.text.valuedocument.form.text.value=text + "P";}function q(){var text=document.form.text.valuedocument.form.text.value=text + "Q";}function r(){var text=document.form.text.valuedocument.form.text.value=text + "R";}function s(){var text=document.form.text.valuedocument.form.text.value=text + "S";}function t(){var text=document.form.text.valuedocument.form.text.value=text + "T";}function u(){var text=document.form.text.valuedocument.form.text.value=text + "U";}function v(){var text=document.form.text.valuedocument.form.text.value=text + "V";}function w(){var text=document.form.text.valuedocument.form.text.value=text + "W";}function x(){var text=document.form.text.valuedocument.form.text.value=text + "X";}function y(){var text=document.form.text.valuedocument.form.text.value=text + "Y";}function z(){var text=document.form.text.valuedocument.form.text.value=text + "Z";}function space(){var text=document.form.text.valuedocument.form.text.value=text + " ";}// --></SCRIPT><form name="form">  <p align="center"><textarea name="text" rows="10" cols="50"></textarea></p>  <p align="center"><input type="button" name="B1" value=" Q " OnClick="q()"><input  type="button" name="B2" value="W" OnClick="w()"><input type="button"  name="B3" value="E" OnClick="e()"><input type="button" name="B4" value="R" OnClick="r()"><input  type="button" name="B5" value="T" OnClick="t()"><input type="button"  name="B6" value="Y" OnClick="y()"><input type="button" name="B7" value="U" OnClick="u()"><input  type="button" name="B8" value=" I " OnClick="i()"><input type="button"  name="B9" value="O" OnClick="o()"><input type="button" name="B10" value="P" OnClick="p()"></p>  <p align="center"><input type="button" name="B11" value="A" OnClick="a()"><input  type="button" name="B12" value="S" OnClick="s()"><input type="button"  name="B13" value="D" OnClick="d()"><input type="button" name="B14"  value="F" OnClick="f()"><input type="button" name="B15" value="G" OnClick="g()"><input  type="button" name="B16" value="H" OnClick="h()"><input type="button"  name="B17" value="J" OnClick="j()"><input type="button" name="B18"  value="K" OnClick="k()"><input type="button" name="B19" value="L" OnClick="l()"></p>  <p align="center"><input type="button" name="B20" value="Z" OnClick="z()"><input  type="button" name="B21" value="X" OnClick="x()"><input type="button"  name="B22" value="C" OnClick="c()"><input type="button" name="B23"  value="V" OnClick="v()"><input type="button" name="B24" value="B" OnClick="b()"><input  type="button" name="B25" value="N" OnClick="n()"><input type="button"  name="B26" value="M" OnClick="m()"></p>  <p align="center"><input type="button" name="B27"  value="" OnClick="space()"></p><INPUT TYPE="hidden" name="hidden"></form></body></html>

希望本文所述對大家的javascript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.