Javascript 获取页面上选中的文字
IE可以调用:
<script type="text/javascript">
// 说明:获取页面上选中的文字
// 整理:http://www.CodeBit.cn
function getSelectedText() {
if (window.getSelection) {
// This technique is the most likely to be standardized.
// getSelection() returns a Selection object, which we do not document.
return window.getSelection().toString();
}
else if (document.getSelection) {
// This is an older, simpler technique that returns a string
return document.getSelection();
}
else if (document.selection) {
// This is the IE-specific technique.
// We do not document the IE selection property or TextRange objects.
return document.selection.createRange().text;
}
}
</script>
在 FireFox 下获取 input 或者 textarea 中选中的文字,可以用下面的方法:
<script type="text/javascript">
// 说明:FireFox 下获取 input 或者 textarea 中选中的文字
// 整理:http://www.codebit.cn
function getTextFieldSelection(e) {
if (e.selectionStart != undefined && e.selectionEnd != undefined) {
var start = e.selectionStart;
var end = e.selectionEnd;
return e.value.substring(start, end);
}
else return ""; // Not supported on this browser
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD
相关文档:
删除行
<script>
function del(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body& ......
1. document.write( " "); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document- >html- >(head,body)
4.一个浏览器窗口中的DOM顺序是:window- >(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById( "表单 ......
String.replace(regexp, replaceText); 这是String类中的replace方法原型
replace方法接受两个参数:
regexp: 正则表达式, 用来在字符串中搜索的规则.
replaceText: 用来替换字符串中匹配正则表达式的子串的字符串
在JavaScript中, 支持正则替换, 正则替换的规则如下:
$$: 原意打印一个$符号
$&: 与规则匹配的整个 ......
1.document.write( " "); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document- >html- >(head,body)
4.一个浏览器窗口中的DOM顺序是:window- >(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById( "表单中元素的ID號 ").name(或value)
6.一个 ......