keyup

keyup event is working slow performance

落花浮王杯 提交于 2019-12-01 07:28:24
问题 My example: $(document).on('keyup', '[contenteditable=true]', function (e) { let _this = $(this), text = _this.text(); if (text.length === 1) { let span = $('<span>').text(text); _this.html(span); } console.log(_this.html()); }); [contenteditable=true] { border: 1px solid #ccc; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> <div contenteditable="true"></div> My problem: If I type some text (more than 1 character) with normal speed into the div, code

jquery: percentage of two numbers

旧巷老猫 提交于 2019-12-01 04:45:17
EDITED Thank you for everyone who offered support... the best working script I will share with you in hope that I could help others who is looking for the same solution: $(document).ready(function(){ $("#price1, #price2").keyup(function() { var priceOne = parseFloat($("#price1").val()); var priceTwo = parseFloat($("#price2").val()); var rate = parseFloat($("#rate").val()); if ($("#price1").val() && $("#price2").val()){ $('#rate').val(((priceTwo - priceOne) / priceOne * 100).toFixed(2)); } }); $("#rate").keyup(function() { var priceOne = parseFloat($("#price1").val()); var rate = parseFloat($("

Google Chrome change event in input is not fired if char added on keyup

混江龙づ霸主 提交于 2019-12-01 04:17:57
$('input#not-gonna-work').bind({ keyup: function(){ console.log('Typed a key'); $(this).val($(this).val() + '.');// try with any other char }, change: function(){ console.log('I\'m a changed input'); } }); I staged this bug in this simplified jsfiddle example. My problem related to this bug is that I have a financial app that I'm building and I need to display a "Save changes" button if input data is changed. Since I need to insert thousand separator immediately on keyup (if needed) this bug really annoys me and breakes that functionality. To reproduce it go to jsfiddle example, open console

jQuery keyup function doesnt work?

会有一股神秘感。 提交于 2019-12-01 04:10:55
My HTML file: <html> <head> <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="js/scripts.js"></script> <link rel="stylesheet" type="text/css" href="style.css" /> <title> Login </title> </head> <body> <div class=loginForm> <p>Worker-ID:<input type=text id=workerID name=workerID /></p> <p>Password:<input type=password id=workerPassword name=workerPassword /></p> <input type=submit id=submitLogin name=submitLogin value="Log in"/> </div> </body> </html> My scripts.js: $('#workerID').keyup(function() { alert('key up'); ); It doesn't work at

Google Chrome change event in input is not fired if char added on keyup

喜欢而已 提交于 2019-12-01 01:31:08
问题 $('input#not-gonna-work').bind({ keyup: function(){ console.log('Typed a key'); $(this).val($(this).val() + '.');// try with any other char }, change: function(){ console.log('I\'m a changed input'); } }); I staged this bug in this simplified jsfiddle example. My problem related to this bug is that I have a financial app that I'm building and I need to display a "Save changes" button if input data is changed. Since I need to insert thousand separator immediately on keyup (if needed) this bug

C# hold key in a game application

空扰寡人 提交于 2019-11-30 15:31:35
问题 I'm trying to make a C# application, which is going to control a game. That I'm trying to do is for example: Hold key A for 150ms, Hold left arrow for 500ms and so on. I was searching a lot and I found the following code. My program firstly target the game and then holding the keys. I'm holding the keys this way: Keyboard.HoldKey(Keys.Left); Thread.sleep(500); Keyboard.ReleaseKey(Keys.Left); Here is the Keyboard class: public class Keyboard { public Keyboard() { } [StructLayout(LayoutKind

C# hold key in a game application

落花浮王杯 提交于 2019-11-30 14:59:50
I'm trying to make a C# application, which is going to control a game. That I'm trying to do is for example: Hold key A for 150ms, Hold left arrow for 500ms and so on. I was searching a lot and I found the following code. My program firstly target the game and then holding the keys. I'm holding the keys this way: Keyboard.HoldKey(Keys.Left); Thread.sleep(500); Keyboard.ReleaseKey(Keys.Left); Here is the Keyboard class: public class Keyboard { public Keyboard() { } [StructLayout(LayoutKind.Explicit, Size = 28)] public struct Input { [FieldOffset(0)] public uint type; [FieldOffset(4)] public

iOS 9 - keyup event not firing

自古美人都是妖i 提交于 2019-11-30 14:02:05
问题 Is anybody else having problems with the keyup event in iOS 9 not firing? Just a simple test bed replicates the issue for me. <input id="txtInput" /> Vanilla JS: document.getElementById('txtInput').onkeyup = function () { console.log('keyup triggered'); } jQuery: $('#txtInput').on('keyup', function () { console.log('keyup triggered'); }); Neither fire... 回答1: I suggest using the keypress event on browsers with touch screens. I know that you can't really detect touch screen screens, though, so

jquery keyup function check if number

∥☆過路亽.° 提交于 2019-11-30 08:10:22
问题 i am trying to create an input field where the user can only type in numbers. this function is already working almost fine for me: $('#p_first').keyup(function(event){ if(isNaN(String.fromCharCode(event.which))){ var value = $(this).val(); $(this).val(value.substr(0,value.length-1)); } }); but the problem is, whe the user holds the key with an character the function keyup is not triggering.... any ideas how i can forbid this? 回答1: Try binding to the keypress event instead of keyup . It gets

keydown + keyup events for specific keys

老子叫甜甜 提交于 2019-11-30 03:54:03
I'm trying to make the background color change when certain keys are held down. For example, when the 'r' key is being held down, the background should be red. When the 'r' key is not being pressed anymore, the background should default to white. $(document).ready(function () { $('body').keydown(function(e){ if(e.keyCode == 114){ $(this).css({'background':'red'}); } if(e.keyCode == 121){ $(this).css({'background':'yellow'}); } }); $('body').keypress(function(e){ if(e.keyCode == 114){ $(this).css({'background':'red'}); } if(e.keyCode == 121){ $(this).css({'background':'yellow'}); } }); $('body'