JS to move through the keyboard click event to achieve DIV

Source: Internet
Author: User

Page content: Text box simulation keyboard Click on the div element to achieve mobile;

<body><textarea id="myarea" ti></textarea>"  mydiv "title="dddddiv"></div></body>

The div style can be defined by itself;

The JS script code is as follows:

Div moves to the left 10px when the keyboard enters ' a ' or ' a '

Script type= "Text/javascript" >varMyarea = document.getElementById ("Myarea");varMydiv = document.getElementById ("mydiv");//Event is a keyboard events object that can recognize which key is pressed aftervarA =Mydiv.offsetleft;//var a = mydiv.offsetwidth;//var a = window.getComputedStyle (mydiv). Left;Myarea.onkeypress =function(event) {//alert (event.keycode);//var odiv = document.getElementById ("mydiv");//Alert (Odiv.getattribute ("title"));if(Event.keycode = = "All" | | event.keycode = = "97") {a=a-10;//var B = a + "px";//alert (a);vari = "20px"Mydiv.style.left= a + "px";}}</script>

JS to move through the keyboard click event to achieve DIV

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.