【www.bbyears.com--浏览器】
下面是从一个网外网站找到的兼容ie6 7 8,ff等浏览器的textarea光标位置两个实现,有需要的朋友可参考。
<script type="text/网页特效">
function RemoveContent () {
var srcObj = document.getElementById ("src");if (document.createRange) { // all browsers, except IE before version 9
var rangeObj = document.createRange ();
rangeObj.selectNodeContents (srcObj);
rangeObj.deleteContents ();
}
else { // Internet Explorer before version 9
var rangeObj = document.body.createTextRange ();
rangeObj.moveToElementText (srcObj);
rangeObj.select ();
rangeObj.execCommand ("cut");
}
}
</script>
The contents of the source element.
方法二
<script type="text/javascript">
function TestSelection () {
if (window.getSelection) { // all browsers, except IE before version 9
var selectionRange = window.getSelection ();
alert ("The text content of the selection:n" + selectionRange.toString ());
}
else {
if (document.selection.type == "None") {
alert ("No content is selected, or the selected content is not available!");
}
else {
var textRange = document.selection.createRange ();
alert ("The text content of the selection:n" + textRange.text);
}
}
}
</script>
Select some text or , or do not select anything, before you click on the button below.