What is the easiest method to get the selection in input text field?
How could I get the selected text in the following code ?
I working with Firefox 3.6.3 (currently not interested in other browsers).
HTML:
<input id="my_text_field" type="text" />
<div id="log"></div>
JavaScript:
$("#my_text_field").select(开发者_运维知识库function() {
var selected_text = "Something selected"; // What should be here ?
$("#log").append(selected_text + "<br />");
});
Check out this other SO post. Hope this helps. ;)
How to get selected text from textbox control with javascript
Have a look at this plugin:
http://labs.0xab.cd/jquery/fieldselection/0.2.3-test/test.html
精彩评论