Jquery/Javascript datepicker concept plugin
I'm trying to imitate the function of the datepicker on how the focus, blur, and click works. focus: when the cursor is at the text field the datebox appear blur: when the cursor is not in the text field the datebox disappear click: when the user clicks the datebox disappear and new value in textfield
I'm trying to create a similar concept: focus: when cursor is at the text field, a div with an icon will appear blur: icon will disappear click: when the icon is clicked, a certain logic code will be executed.
PROBLEM: WHEN I TRY TO CLICK THE ICON, THE BLUR EVENT IS FIRST BEING CALLED, SO THE CLICK EVENT NEVER FIRES,
here is my code:
div.searchHelp table tbody tr:hover{ background:orange; } div.searchHelp table tbody tr:active{ background:red; } div.searchHelp table tbody tr td._key{ background:green; }
I hope to get help from you guys, thanks
If you change your
searchIcon.click(function(){
to
searchIcon.mousedown(function(){
mousedown fires before focus is lost on the input. This will however still hide the icon after your mousedown runs. If you do not want the icon to disappear after it is clicked, have your mousedown set a flag, then have your blur check that flag. Something like this:
var iconClicked=false;
searchIcon.mousedown(function(){
...
iconClicked=true;
}
$this.bind("blur",function(){
if(iconClicked){
iconCLicked=false;
}else{
searchIcon.hide();
}
});
The only drawback is that this is on mousedown and not on click, but depending on what you're trying to do this may be acceptable.
EDIT: Found this, the first suggestion is an interesting one. jQuery Blur Fires Before href
精彩评论