google chrome does not fire blur event on radio buttons?

て烟熏妆下的殇ゞ 提交于 2019-12-01 17:01:10

问题


This is my first post here - hello everybody

I am currently developing a html form with the support of css and jquery. The form will be used by 'unexperienced users' so my focus lies on good usability. Therefor I am providing a hint to every input field with further instructions. To show the hints I am using the onfocus/onblur javascript event, so only one hint at a time is shown. This worked well when I only had input fields of type="text", but with input fields of type="radio" I am experiencing troubles in google chrome.

I made a quick example on jsfiddle.net so you can see what I mean. The code there is very similar to the code I use in my form, so I didn't bother to post it here. The alert pops up in every browser I tested so far except google chrome. I wonder why? Is there any known solution or workaround to it?


回答1:


Working sample:

$('input').on({
    click: function (e) {
        this.focus();
        $('#' + this.id + 'msg').show();
    },
    blur: function (e) {
        $('#' + this.id + 'msg').hide();
    }
});



回答2:


From quirksmode:

Safari and Chrome do not fire focus/blur events when the user uses the mouse to access checkboxes, radios or buttons. Text fields, textareas and select boxes work correctly.

There are a few suggestions to work around this here.




回答3:


blur will work on certain versions of Chrome (but not mine 10.0.648.205), but only if you move away from the entire collection of elements. Not sure if this is helpful, but this will work:

$('input:radio').click(function() {
    alert('why does this not show up in google chrome?!');
});

HTH.



来源:https://stackoverflow.com/questions/5744825/google-chrome-does-not-fire-blur-event-on-radio-buttons

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