Stopping a blur event on Click of a hyperlink

孤街浪徒 提交于 2019-12-20 05:51:05

问题


I used this answer jQuery <select> simulation with input and div to create a dropdown look alike. I am trying the make the user select only the options displayed in the list and he cannot enter his own value in the field.

If he enters any character in the input field, then a link is displayed with the list hidden and on click of this link, the user entered value in input field is cleared and the list is again displayed to the user and the focus returned to the field.

But, what happens is on click of this link, the list appears and gets blurred immediately. But, i want the list to stay. I used mouseover event to overcome this, but apparently i have been told to use only click event. Here is the code --> http://jsbin.com/uxerus/25/edit

Any insights on this is welcome. thanks!!


回答1:


Try returning focus to the input after the value is updated (demo):

$('#content span').click(function(){
    $('#input').val($(this).html()).focus();
    $('#content').hide();
});

I haven't tested this, but IE will probably move the caret to the beginning while other browsers will move it to the end. To fix that you'll need to use a caret plugin or add a bunch more code.



来源:https://stackoverflow.com/questions/16496709/stopping-a-blur-event-on-click-of-a-hyperlink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!