我想将keypress
个事件绑定到contenteditable
<label>
。这在Firefox中可以正常工作,但在Chrome中,键入<label>
不会触发绑定功能。请注意,这适用于Chrome和Firefox中的<div>
。
Pretty JS Fiddle,raw JS JS Fiddle,相关代码如下:
<label contenteditable>LABEL: This is some content in a label</label>
<div contenteditable id="div">DIV: This is some content in a div</div>
<div id="message">press key</div>
<script>
$(function() {
var eventDetails = function(event) {
$('#message').html(event.type + ' event fired - ' + event.target.tagName);
};
$('label, #div').bind('keypress', eventDetails);
$('label, #div').bind('click', eventDetails);
});
</script>