给定以下条件:
$("#dataField").focus().autocomplete({
minLength:5,
cache:false,
source:"${request.contextPath}/ajaxActions/getdata",
select:function (event, ui) {
populateForm(ui);
}
});
如何更改焦点函数,使其将光标放在输入当前值的末尾?
我还没有真正测试过,但它或多或少应该能满足您的需求。
(function( )
{
var oldFocus = $.fn.focus;
$.fn.focus = function( arg1, arg2 )
{
// ======== Call Old Function
var result = oldFocus.apply( this, arguments );
// ======== Additional Functionality
// Logic here to move your cursor
return result; // -- this preserves ability to chain
}
})( );
要实际移动光标,请参阅SO问题:将光标移动到输入字段的开头?
$("#dataField").focus(function() {
$(this).val($(this.val());
}).focus();
这种方法是jQuery在这个链接中做事情的方式,因此应该做您需要的事情。