Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent focus event in IE when mousedown happens

event.preventDefault(); return false; event.stopPropagation();

any of them can prevent focus event from happening when I trigger a mousedown event in Firefox and chrome, but it failed in IE.In fact,chrome has another problem. when mousedowning, :hover css is not working. `

<input type="text" id="name">
<div id="suggest">
  <div>mark</div>
  <div>sam</div>
  <div>john</div>
</div>
$("#name").focus(suggest.show).blur(suggest.hide);

` what I expected is, when I click the sub div, such as "sam",and then $("#name").val("sam"). but the problem is, when I press the mouse(just mousedown,not released), the $("#name").blur runs immediately and suggest div becomes hide.

like image 834
Jinceon Avatar asked Mar 21 '12 12:03

Jinceon


People also ask

What is mouseDown event in HTML?

Element: mousedown event The mousedown event is fired at an Element when a pointing device button is pressed while the pointer is inside the element. Note: This differs from the click event in that click is fired after a full click action occurs; that is, the mouse button is pressed and released while the pointer remains inside the same element.

What is the difference between focus and focusin in JavaScript?

The main difference between this event and focusin is that focusin bubbles while focus does not. The opposite of focus is blur. There are two ways of implementing event delegation for this event: by using the focusin event, or by setting the useCapture parameter of addEventListener () to true.

What is mouseDown and mouseUp in C++?

MouseDown or MouseUp event procedures specify actions that occur when a mouse button is pressed or released. MouseDown and MouseUp events enable you to distinguish between the left, right, and middle mouse buttons. You can also write code for mouse-keyboard combinations that use the SHIFT, CTRL, and ALT keyboard modifiers.

What is mouseDown and TabStrip?

For a MultiPage, the MouseDown event occurs when the user presses a mouse button over the control. For a TabStrip, the index argument identifies the tab where the user clicked. An index of -1 indicates the user did not click a tab.


1 Answers

You can use "unselectable" attribute for prevent losing focus in IE and mousedown handler for other.

<input type="text" id="name">

<div onmousedown="return false" unselectable="on" id="suggest">
  <div unselectable="on">mark</div>
  <div unselectable="on">sam</div>
  <div unselectable="on">john</div>
</div>
like image 165
nameoutname Avatar answered Oct 01 '22 15:10

nameoutname