jsBin :
http://jsbin.com/eyARuHI/2/edit?html,css,js,output
代码:
$('#in').on('blur', function(event) {
alert('input: ' + event.type);
});
$('#button').on('click', function(event) {
alert('button: ' + event.type);
});
HTML :
<input id='in' type='text'>
<div id='button'></div>
问题:
如果关注输入然后单击按钮 - click
将永远不会被触发。
在这种情况下如何正确处理点击事件?
答案 0 :(得分:0)
正如@RGraham所建议的那样试试JS。每次点击它时,您都会看到按钮事件被触发。
$('#in').on('blur', function(event) {
console.log('input: ' + event.type);
});
$('#button').on('click', function(event) {
console.log('button: ' + event.type);
});
答案 1 :(得分:0)
你需要停止冒泡事件。试试这个
$('#button').on('click', function(event) {
alert('button: ' + event.type);
return false;
});
$('#in').on('blur', function(event) {
alert('input: ' + event.type);
});