<body onload='t1.select()'>
<input type="text" value="1111"/ id='t1'>
<input type='button' onclick='getText()'>
<script>
function getText(){
var sel = document.selection;
if (sel!=null) {
var oRng = sel.createRange();
if (oRng != null)
alert(oRng.text);
}
}
</script>
</body>
<input type="text" value="1111"/ id='t1'>
<input type='button' onclick='getText()'>
<script>
function getText(){
var sel = document.selection;
if (sel!=null) {
var oRng = sel.createRange();
if (oRng != null)
alert(oRng.text);
}
}
</script>
</body>
alert(oSel.text);
{
var txt = '';
var foundIn = '';
if (window.getSelection)
{
txt = window.getSelection();
foundIn = 'window.getSelection()';
}
else if (document.getSelection)
{
txt = document.getSelection();
foundIn = 'document.getSelection()';
}
else if (document.selection)
{
txt = document.selection.createRange().text;
foundIn = 'document.selection.createRange()';
}
else return;
document.forms[0].selectedtext.value = 'Found in: ' + foundIn + '\n' + txt;
}http://www.quirksmode.org/js/selected.html