jquery - Javascript onkeyup too "slow"? .hide() works only with onkeydown -



jquery - Javascript onkeyup too "slow"? .hide() works only with onkeydown -

i using function show div:

function showcmd() { $("#cmd").show("fast"); $('#cmdtext').focus(); }

this happens, if user typing "cmd" on keyboard.

main code:

document.onkeyup = function(event) { //save lastly 3 keys 1 = two; 2 = three; 3 = event.keycode; if (one == 67 && 2 == 77 && 3 == 68 && cmdopen == false) { showcmd(); } //if pressed key come in , textarea focused if (event.keycode == 13 && $("#cmdtext").is(":focus") == true) { //passing code function execcmd(document.getelementbyid("cmdtext").value); //empty textarea - works great document.getelementbyid("cmdtext").value = ""; homecoming false; } }

the code typed in user handled here:

function execcmd(command) { if(command == "exit") $("#cmd").hide("fast"); console.log(command); }

console gives me every time exit. doesn't hide div #cmd. if alter onkeyup onkeydown, works fine. problem onkeydown is, textarea shows "d", after opening command line key sequence "cmd".

so either can't close #cmd or shows "d" every time open #cmd.

last not to the lowest degree html code:

<div id="cmd"> <textarea id="cmdtext" maxlength="80"></textarea> </div>

maybe know solution problem! give thanks far

live demo

you need trim() command, because when type exit, command store exit\n.

js

function execcmd(command) { if(command.trim() == "exit") // add together trim() $("#cmd").hide("fast"); console.log(command); } function showcmd() { $("#cmd").show("fast"); $('#cmdtext').focus(); } document.onkeyup = function(event) { //save lastly 3 keys 1 = two; 2 = three; 3 = event.keycode; // alter order of declaration , definition if (one == 67 && 2 == 77 && 3 == 68 && cmdopen == false) { showcmd(); } //if pressed key come in , textarea focused if (event.keycode == 13 && $("#cmdtext").is(":focus") == true) { //passing code function execcmd(document.getelementbyid("cmdtext").value); //empty textarea - works great document.getelementbyid("cmdtext").value = ""; homecoming false; }

}

javascript jquery html onkeydown onkeyup

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -