Chrome Automatically Moving Focus

2020-04-21 05:16发布

问题:

Got an issue that is specific to Chrome; it's moving the focus from my html inputs to the first user element in a dynamically rendered form.

Example: HTML_SELECT_00 HTML_SELECT_01 INPUT_TEXT_00

Problem: If you place the cursor in INPUT_TEXT_00 (using the mouse), as soon as you let go of the mouse button, the focus will shift back to HTML_SELECT_00. If you tab into INPUT_TEXT_00, the focus does not get 'stolen', and works as desired.

This problem does not occur in FF or in IE7/8. Only in Chrome and my version is up-to-date.

I have two events hooked to the input, onChange and onKeyPress. However, those events are not triggered simply by placing the cursor in them.

I hope someone has seen this before; I've been searching all over for a resolution.

Regards, Randall

回答1:

There's probably a label wrapping the three elements.



回答2:

I had the same problem but there wasn't a label in sight. I fixed this by stopping event bubbling on the mousup event:

jQuery("input").mousup(function(event){
    //more code
    //...
    event.stopPropagation();
});