亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

JQuery在光標(biāo)位置插入內(nèi)容的實現(xiàn)代碼

 更新時間:2010年06月18日 22:35:49   作者:  
IE下可以通過 document.selectIOn.createRange ();來實現(xiàn),而Firefox(火狐)瀏覽器則 需要首先獲取光標(biāo)位置,然后對value進(jìn)行字符串截取處理
復(fù)制代碼 代碼如下:

(function($){
$.fn.extend({
insertAtCaret: function(myValue){
var $t=$(this)[0];
if (document.selection) {
this.focus();
sel = document.selection.createRange();
sel.text = myValue;
this.focus();
}
else
if ($t.selectionStart || $t.selectionStart == '0') {
var startPos = $t.selectionStart;
var endPos = $t.selectionEnd;
var scrollTop = $t.scrollTop;
$t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
this.focus();
$t.selectionStart = startPos + myValue.length;
$t.selectionEnd = startPos + myValue.length;
$t.scrollTop = scrollTop;
}
else {
this.value += myValue;
this.focus();
}
}
})
})(jQuery);

使用方法:
復(fù)制代碼 代碼如下:
$(selector).insertAtCaret("value");

相關(guān)文章

最新評論