原文地址:http://stackoverflow.com/questions/6391997/onblur-killing-onclick-but-not-if-settimeout-is-used
If you put cursor in the first input, then click the button, you get one message.
If you put the cursor in the second one (with the setTimeout
), you get both messages.
Why doesn't the 'button was clicked' message display in the first scenario?
Conversely, what is it about the setTimeout
that makes the second one show both alerts?
<html>
<head>
<script type='text/javascript'>
function testOne() {
alert('button was clicked');
}
function testTwo() {
alert ('focus left the input');
}
</script>
</head>
<body>
<input name="input1" οnblur="testTwo()" />
<input name="input2" οnblur="setTimeout(function(){testTwo();}, 100)" />
<button name="button1" οnclick="testOne()">Button</button>
</body>
</html>
英文不太好,就是给大家一个思路吧。感谢国外友人的分享,技术无国界。同时希望国内的论坛氛围能好一点,自己在别人的帮助下找到了解决方案,也可以用解决方案来结贴。国内论坛好多楼猪都是这么结尾:“我已自己找到解决方案,谢谢大家...然后没有然后了···
大家有不同意见,可以交流下····