当用户离开当前输入字段时,我的HTML表单正在执行一个操作(向表单中添加一条新行,以便能够输入另一个电话号码)。
当使用IE执行时,此代码会造成很大的滞后:
$("#createOrUpdateContactPersonPhoneNumber0").on('focusout', function() {
addAnotherRow();
});
function addAnotherRow() {
$("#phoneNumberTable tr:last-child").before('<tr><td><select style="width: 100px;" id="createOrUpdateContactPersonPhoneType' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"></select></td><td><select id="createOrUpdateContactPersonPhoneCountry' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"></select></td><td><input style="height: 21px;" type="text" id="createOrUpdateContactPersonPhoneNumber' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"/></td><td><input style="height: 21px; width: 100px;" type="text" id="createOrUpdateContactPersonPhoneExtension' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"/></td><td><select id="createOrUpdateContactPersonPhonePurpose' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"></select></td><td><center><input type="radio" name="createOrUpdateContactPersonPhonePrimary" id="createOrUpdateContactPersonPhonePrimary' + $("#phoneNumberTable tr:not(:first-child):not(:last-child)").length + '"/></center></td><td></td></tr>');
};当将函数"addAnotherRow()“的代码直接添加到.on('focusout')事件时,没有任何滞后。
发布于 2014-10-23 07:40:23
使用onBlur而不是onFocusOut。请注意,onBlur不冒泡。
https://stackoverflow.com/questions/26523304
复制相似问题