function getSelectText(editor) {
if (!editor) return editor.focus()
if (editor.document && editor.document.selection)
return editor.document.selection.createRange().text
else if ("selectionStart" in editor)
return editor.value.substring(editor.selectionStart, editor.selectionEnd)
}
//调用方式
var text= getSelectText(document.getElementById("txtName"))
有如下的文本框:
<input name="jbxue_form" id="jbxue_form" value="内容" /> <script>//JS选中文本框中内容
document.getElementById("jbxue_form").focus()
document.getElementById("jbxue_form").select()
//jquery选中文本框中内容
$("#jbxue_form").focus()
$("#jbxue_form").select()
</script>