选择文本事件
2008-09-26 16:07
120 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>选择事件</title>
</head>
<body>
武汉
<div><span>湖北</span></div>
<div><span>中国</span></div>
</body>
<script type="text/javascript">
var K = K || {};
K.SelectEvent = function(e) {
var q = K.GetSelectText();
if ('' == q) return true;
alert(q);
};
K.GetSelectText = function() {
var q = '';
try {
if (window.getSelection) {
q = window.getSelection();
} else if (document.getSelection) {
q = document.getSelection();
} else if (document.selection) {
q = document.selection.createRange().text;
} else {
q = '';
}
q = q.toString();
q = q.replace(/((^/s*)|([/n/t/r]+)|(/s*$))/g, '');
if (q.replace(/[^/x00-/xff]/g, "**").length > 15) {
return '';
q = q.substr(0, 15);
}
} catch(e) {}
return q;
};
if (document.addEventListener) {
document.addEventListener("mouseup", K.SelectEvent, true);
} else if (document.attachEvent) {
document.attachEvent("onmouseup", K.SelectEvent);
} else {}
</script>
</html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>选择事件</title>
</head>
<body>
武汉
<div><span>湖北</span></div>
<div><span>中国</span></div>
</body>
<script type="text/javascript">
var K = K || {};
K.SelectEvent = function(e) {
var q = K.GetSelectText();
if ('' == q) return true;
alert(q);
};
K.GetSelectText = function() {
var q = '';
try {
if (window.getSelection) {
q = window.getSelection();
} else if (document.getSelection) {
q = document.getSelection();
} else if (document.selection) {
q = document.selection.createRange().text;
} else {
q = '';
}
q = q.toString();
q = q.replace(/((^/s*)|([/n/t/r]+)|(/s*$))/g, '');
if (q.replace(/[^/x00-/xff]/g, "**").length > 15) {
return '';
q = q.substr(0, 15);
}
} catch(e) {}
return q;
};
if (document.addEventListener) {
document.addEventListener("mouseup", K.SelectEvent, true);
} else if (document.attachEvent) {
document.attachEvent("onmouseup", K.SelectEvent);
} else {}
</script>
</html>
相关文章推荐
- textarea文本选择onselect事件初探
- js 事件-设置不能在窗口点击右键和选择文本事件
- 下拉框改变事件:获取下拉框中当前选择的文本 SelectionChanged事件
- 选择文本触发事件
- 【译】 AWK教程指南 4通过文本内容和对比选择指定的记录
- 3.9触摸事件分发的例子-选择英雄图标,切换对应英雄,控制其移动。
- JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参(selected的值和页面其它元素的值)
- jQuery取得select选择的文本与值
- Flex的TextArea控件中如何利用setSelection事件设定文本选中范围的例子
- 文本分类入门(十一)特征选择方法之信息增益
- jQuery1.9为动态添加元素绑定事件以及获取和操作checkbox的选择属性
- Gridview 选择行时触发的事件
- 扩展GridView实现多选(全选)、点击行任意位置选择行、选中变色、添加双击事件等
- JList监听,选择会得到两次事件
- js从text或textarea文本框中选择部分文本,并取得选择的内容
- jQuery取得select选择的文本与值的示例
- flexigrid 添加行选择事件
- iOS UITextField 获得焦点后,阻止弹出键盘事件,显示时间选择器
- abap 选择屏幕事件AT SELECTION-SCREEN
- flexigrid checkbox选择事件