JavaScript DHTML/Document/Selection
Версия от 09:59, 26 мая 2010; (обсуждение)
Clear a selection
<head>
<script language="JavaScript">
function function1() {
document.selection.clear();
}
</script>
</head>
<body>
<p id="myP" contenteditable>
Select any part of it and click the button below.</p>
<button onclick="function1();">Delete selection</button>
</body>
</html>
Empty a selection
<html>
<body>
<script language="JavaScript">
function function1() {
document.selection.empty();
}
</script>
<p onMouseUp="function1();">you release the mouse.</p>
<p>You can select text in this paragraph in various places.</p>
</body>
</html>
Selection type
<html>
<body onclick="alert(document.selection.type);">
<p>Select any element in the page</p>
<input type="text" value="Some text">
<input type="button" value="Some button">
</body>
</html>
Selection type Detail Example
<html>
<body>
<p>Select a portion of the sample text here. Then click the button</p>
<input type="button" value="Click here" onclick="alert(document.selection.typeDetail);">
</body>
</html>