对于页面内的文字,单击选中,对于元素内的文本不会起效

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table border="1" width="71%"  >
  <tr>
    <td width="212" height="52" onclick="selectPageText(this)">单击我选中文本</td>
    <td width="179" >测试</td>
    <td width="213">测试</td>
  </tr>
</table>
</body>
</html>
<script type="text/javascript" language="javascript">
//选中某元素文本(只能是页面当中的文本,元素内的文本不会被选中)
function selectPageText(selectElement)
{
	//声明一个文本范围
	var rng=document.body.createTextRange(); 
	//移动到某元素的文本
	rng.moveToElementText(selectElement);
	//选中
	rng.select(); 
}
</script>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2021-08-23
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案