2016-07-26 16 views
0

我使用jquery easyui來幫助我完成項目。但是,當我使用ie10,即ie11和最新版本的Firefox來測試編輯表單時,會出現問題。jquery easyui,ie10,ie11,firefox,輸入中的默認光標位置是否爲0?

當我使用firefox並點擊了,它被聚焦,但光標位置爲0,在輸入值的頭部。 當我使用ie時,我需要雙擊才能對焦,並且位置與firefox相同。

如何設置輸入值結束時的默認光標位置?

回答

1

可以綁定一個焦點事件,將光標移動到結束

// simple 
<input onfocus="moveCursorToEnd(this)" /> 
// better to bind with jquery 
$("input[type='text']").on("focus", function(){ 
    moveCursorToEnd(this); 
}); 
// delegate 
$("#form").on("focus", "input", function(){ 
    moveCursorToEnd(this); 
}); 


function moveCursorToEnd(el) { 
    if (typeof el.selectionStart == "number") { 
     el.selectionStart = el.selectionEnd = el.value.length; 
    } else if (typeof el.createTextRange != "undefined") { 
     el.focus(); 
     var range = el.createTextRange(); 
     range.collapse(false); 
     range.select(); 
    } 
} 
+0

$( 「輸入[類型= '文本']」) .on(「focus」,function()var that = $(this); var value = that.val(); that.val(「」); that.val(value); }) ; – footoss

+0

這需要雙擊以使輸入與ie10,ie11和邊緣集中。 – footoss

+0

焦點事件在元素設置爲焦點時觸發 - 而不是點擊時。上面的JQuery代碼行與(this.value = this.value;)一樣,也可能會將遊標移動到最後一些情況。 – Steve

0

iconCls =「圖標保存」緩存=「假」調整大小=「真」模式=「真正的」可拖動=「假「closed =」true「

可拖動的數據選項應被刪除。

像: iconCls = 「圖標保存」 緩存= 「假」 可調整大小= 「真」 模式= 「真」 閉合= 「真」