用document.selection.createRange().text, 试下面这个例子,选好文字后,按GET按钮:<html> <head> <script> function GetSelection() { alert(document.selection.createRange().text); } </script> </head> <body> The world racism <span>conference has adopted <span>a final declaration recognising the injustice of slavery and colonialism and the "plight" of Palestinians after nine days of recrimination and brinksmanship. <br> <input type="button" value="Get" onclick="GetSelection()": </body> </html>
<head>
<script>
function GetSelection()
{
alert(document.selection.createRange().text);
}
</script>
</head>
<body>
The world racism <span>conference has adopted <span>a final declaration recognising the injustice of slavery and colonialism and the "plight" of Palestinians after nine days of recrimination and brinksmanship.
<br>
<input type="button" value="Get" onclick="GetSelection()":
</body>
</html>