我有以下代码来初始化x-editable。问题是后期渲染部分。点击输入时我不需要setTimeout来设置焦点/选择;但是当调用price_to_change.editable('show');
时,后期渲染功能仍在运行;但是我需要setTimeout来进行选择
$.fn.editable.defaults.mode = 'popup';
$('.xeditable').editable({
validate: function(value) {
if ($.isNumeric(value) == '' && $(this).data('validate-number')) {
return 'Only numbers are allowed';
}
},
success: function(response, newValue) {
$("#register_container").html(response);
},
});
$('.xeditable').on('shown', function(e, editable) {
editable.input.postrender = function() {
//setTimeout is only needed when calling .editable('show') as shown below
setTimeout(function() {
editable.input.$input.select();
}, 10);
};
var price_to_change = $('#register a[data-name="price"]').first();
price_to_change.editable('show');