使用HTML和javascript做的取词效果

本文提供了一个结合HTML与JavaScript的代码示例,展示了如何在用户选择文本后显示所选内容,通过简单的网页布局和交互功能说明了基本的网页开发技巧。

没有什么多说的直接附上code了,仅供参考:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style type="text/css">
.code{
   margin: 5px;
   padding: 10px;
   border: 1px solid #87BF23;
   background-color: #eee;
   font-size: 12px;
}
</style>
<script type="text/javascript">
function $(id){
   return document.getElementById(id);
}
function getSelectText()
{
   var txt = null;
   if (window.getSelection){ // mozilla FF
    txt = window.getSelection();
   }else if (document.getSelection){
    txt = document.getSelection();
   }else if (document.selection){ //IE
    txt = document.selection.createRange().text;
   }
   return txt;
}
</script>

</HEAD>

<BODY>
<p>效果演示区</p> <div class="code" onmouseup="javascript:f()"> <p>内容开始:As a result, I am pleased to announce a reorganization that will give some of our smaller business units greater scale. It will also allow us to integrate certain activities that we perform today in each unit into a country-wide organization. At the business level, we will consolidate six units into four: Healthcare, Consumer, Enterprise and Telecom (which now integrates Wireless) - all reporting to Sanjay Singh. We will also formalize the position of country heads in India, Ukraine and China - all reporting to Mukul Jain along with select global function heads. To be clear, these changes are not in anticipation of shrinkage but to better position us for growth. This new organization structure will ensure that our units are built around cohesive markets, which is good for our clients. It will also ensure that countries and product engineering centers will operate in a more integrated fashion, which is good for our employees. It will also support the more rapid adoption of global systems and processes. To learn more, please refer to the Re-organization Summary section below.</p> </div> <p>&nbsp;</p> <div id="rs_081125" class="code">您选取的内容是:</div> <script type="text/javascript"> /*<![CDATA[*/ function f(){ var txt = getSelectText(); if(txt!=null){ $("rs_081125").innerHTML="您选取的内容是:<br />"+txt; } } /*]]>*/ </script>
</BODY>
</HTML>s

转载于:https://www.cnblogs.com/majian714/archive/2011/11/28/2265759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值