javascript中如何获得选中文字所在的节点 javascript中如何获得选中文字所在的节点在:<div>12345677aaaaa888888</div>中,我在页面里面选中aaaaa,如果获得DIV这个节点? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 jquery的选择器是可以,那么原始的js当然也可以,不过还是用jquery方便 $("div:contains('aaaaa')"),直接给你个例子 <!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> new document </title> <script type="text/javascript"> <!-- function ShowDirection() { var tbl = []; var direct = (document.selection && document.selection.createRange) ? document.selection.createRange().parentElement() // IE : window.getSelection().focusNode.parentNode; // FF alert(direct.tagName + ': ' + direct.innerHTML); } //--> </script> </head> <body> <div>12345677aaaaa888888 </div> <input type="button" value="ShowDirection" onclick="ShowDirection()" /> </body></html> 关于jquery的一个问题 div适应li的宽度问题 字幕的数据结构问题?求解决 javaScript 很急 求 JS 幻灯 相似的也行 (潜水多年,终于忍不住提问下)类似chinaren登录的效果如何实现? 怎么动态读取数据库 形成多级树状列表 帮忙修改一下悬浮脚本... 如何判断一个变量是不是数组 请问如何固定表头? JQuery合并表格中相同内容的单元格 jQuery如何判断后面兄弟级元素是否存在?
<!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> new document </title>
<script type="text/javascript">
<!--
function ShowDirection() {
var tbl = [];
var direct = (document.selection && document.selection.createRange)
? document.selection.createRange().parentElement() // IE
: window.getSelection().focusNode.parentNode; // FF
alert(direct.tagName + ': ' + direct.innerHTML);
}
//-->
</script>
</head> <body>
<div>12345677aaaaa888888 </div>
<input type="button" value="ShowDirection" onclick="ShowDirection()" />
</body>
</html>