(function($){
$.fn.extend( {
insertAtCaret: function(myValue){
var $t=$(this)[0];
if (document.selection) {
this.focus(); document.selection.createRange();
sel.text = myValue;
}
else
if ($t.selectionStart || $t.selectionStart = = '0') {
var startPos = $t.selectionStart;
var rollTop = $t.scrollTop; value.substring(0, startPos) myValue $t.value.substring(endPos, $t.value.length);
$t.selectionStart = startPos $t.selectionEnd = startPos myValue.length;
$t.scrollTop =scrollTop;
else {
this.value = myValue(); >}
}
})
})(jQuery);
使用方法:
复制代码
代码如下:
$(selector ).insertAtCaret("値");