I'm trying to get the non selected text in an Input Text element using IE8, I tried this and was really helpfully, but in the case of the text wasn't selected the function returns the index of start and end of the string.
How can I get the non selected text of the input text element or how can I know when there isn't text selected?
Using jQuery would be helpfully too.
If I've understood your question correctly, you'll need something like this:
function getNonSelectedText(){
var elem=document.getElementById('input');
var selection=document.selection;
var range=selection.createRange();
if(range.boundingWidth<1){
return elem.value;
}
var rangePre=range.duplicate();
rangePre.moveToElementText(range.parentElement());// For <textarea>
// rangePre.expand('textedit'); // For <input type=text>
var rangePost=rangePre.duplicate();
rangePre.setEndPoint('EndToStart',range);
rangePost.setEndPoint('StartToEnd',range);
return rangePre.text+rangePost.text;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.