making onchange work like onchange and not like onleave?
I have this piece of code:
<input type="text" name="desc开发者_C百科" id="desc" onchange="OnDescChange();" />
but it does not act as i want. It runs the function when i leave the box, i would like to do it everytime the content of that inputfield changes, how do i do that?
(im trying to make a suggestionbox to the users input).
Ive also tried jquerys .change but it gives med the same result.
Try onKeyUp or onKeyPress.
Try to use the onkeypress
event:
<input type="text" name="desc" id="desc" onkeypress="OnDescChange();" />
I would recomment using the onkeyup event handler
<input type="text" name="desc" id="desc" onkeyup="OnDescChange();" />
onkeydown or onkeypress could be used too, but the only problem to be aware of with that is that these event fires before the text in the input field has been updated.
You can use 'onKeyUp' or 'onKeyDown' events instead of 'onchange'
If you are using jquery you can use something like the following
$("input").keyup(function(){
$("input").css("background-color","#D6D6FF");
});
Hope this helps.
精彩评论