<script language=javascript> function getSelText() { var txt = ''; if (window.getSelection) { txt = window.getSelection(); } else if (document.getSelection) { txt = document.getSelection(); } else if (document.selection) { txt = document.selection.createRange().text; }
return txt;
}
function haha(){ var obj=document.getElementById('test');
if(getSelText()==obj.value){
}else{ obj.select(); } }
</script> <input value="xuzhedantest" id='test' onmouseup="haha()" />
<input type="button" value="Get selection" onmousedown="getSelText()"> <form name=aform > <textarea name="selectedtext" rows="5" cols="20"></textarea> </form>
|