我在我的Web应用程序中有一个“可编辑表格”。它的工作原理是,当你点击表的td时,我读取了td的innerHTML,并生成一个输入字段,我用innerHTML的值注入td。iOS Safari内存泄露使应用程序无法使用
当您对输入字段进行模糊/聚焦时,我会销毁输入字段并设置新值的innerHTML,并发送AJAX请求来更新该字段。这在桌面和Android手机上完美运行,但在iOS Safari中,您编辑的值越多,它越慢。约。 250次编辑,滚动会变得非常不连贯,最终页面几乎变得无法使用。页面刷新不能解决问题,它需要您完全关闭网页并重新开始。
这使我相信Safari并没有释放被破坏的输入字段的内存。
相关的JavaScript代码在下面给出,就点击触发对TD:
_handleEditing: function($td) {
var value = $td.find("span").html().replace(",", ""),
ctrl = this;
$td.unbind('click');
// Clone the input control
var $editControl = $('#input .edit-control').clone();
if(this.isMobile) {
$editControl.attr('type', 'number');
$editControl.attr('step', '0.01');
}
// Inject editControl into td html and set appropriate values
$td.html($editControl);
$editControl.val(value);
// Focus the edit control and set the selection range
$editControl.focus();
setTimeout(function() {
$editControl.get(0).setSelectionRange(0, value.length);
}, 0);
firstKeydown = true;
// Handle leaving the input field and returning to normal number
$editControl.on('blur', function(){
var newValue = $editControl.val();
// If the newValue is empty, go back to the old value
newValue = (newValue === '') ? value : newValue;
var parsedNewValue = parseFloat(newValue).toFixed(2);
// If the newValue is not actually a number, go back to the old value
newValue = isFinite(parsedNewValue) ? parsedNewValue : value;
$editControl.unbind().remove();
$editControl = null;
$td.html("<span>"+newValue+"</span>");
// Queue this value update to server
if(parseFloat(newValue) !== parseFloat(value)) {
ctrl.handleValueChanged($td, value, newValue);
}
// Reinstate the click handler on the td
$td.click(function(){
ctrl._handleEditing($td);
});
});
this._attachNavigationHandlers($editControl);
},
任何帮助,将不胜感激。 基础上的研究,我已经做了类似的问题(渐进性能下降iOS上的苹果开发者请帮助
虽然此链接可能会回答问题,但最好在此处包含答案的重要部分并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 – Marusyk
这是个好主意,我现在补充一下。 – Vemonus