本文演示了jQuery在光标位置实现内容插入的方式,供大家参考,具体实现方法如下:

复制代码代码如下所示:





无标题页





(函数($){)

fn.extend({美元。

InsertAtCaret:功能(自我价值){

var $ $ =($){ 0 };

如果(文档选择){

This.focus();

SEL = document.selection.createrange();

sel.text =自我价值;

This.focus();

别的}

如果($ t.selectionstart | | t.selectionstart美元= = '0')

{

VaR StartPos = t.selectionstart美元;

VaR EndPos = t.selectionend美元;

VaR scrollTop = $ t.scrolltop;

t.value = t.value.substring(0美元美元,让美元)+自我价值+ t.value.substring(EndPos,t.value美元。长度);

This.focus();

t.selectionstart美元= Startpos + myvalue.length;

t.selectionend美元= Startpos + myvalue.length;

t.scrolltop美元= scrollTop;

{人}

this.value =自我价值;

This.focus();

}

}

})

}(jQuery);

$(文档)Ready(函数(){)

$(# numd)。Bind(MouseLeave

document.getelementbyid('keybored)。Style.display =不关;

Document.getElementById ('Nm').Blur ();

});

$(# nm)。焦点(函数(){)

document.getelementbyid('keybored ' Style.display ');

});

$(。readbtns)。Click(function(){)

$(# nm)。InsertAtCaret($(this)。瓦迩());

});

});



























< DIV style=显示:无;border: 1px solid # a2b4c6;宽度:150px;身高:400px;

id=keybored>



























希望本文能对大家的jQuery程序设计有所帮助。