onkeyup

jQuery key code for command key

主宰稳场 提交于 2019-11-26 10:33:30
问题 I have read jQuery Event Keypress: Which key was pressed? and How can i check if key is pressed during click event with jquery? However my question is if you can get the same key event for all browsers? Currently I know that Firefox gives the command button (Mac) the code 224 while Chrome and Safari give it the value 91. Is the best approach to simply check what browser the user is using and base the key pressed on that or is there a way so that I can get 1 key code across all browsers? Note

Count characters in textarea

梦想与她 提交于 2019-11-26 03:27:40
问题 I want to count characters in a textarea, so I just made: <textarea id=\"field\" onkeyup=\"countChar(this)\"></textarea> function countChar(val){ var len = val.value.length; if (len >= 500) { val.value = val.value.substring(0, 500); } else { $(\'#charNum\').text(500 - len); } }; What\'s wrong with my piece of code? It does not work! Well, that was a newbie handwriting, need a help. 回答1: What errors are you seeing in the browser? I can understand why your code doesn't work if what you posted