首页 > Web开发 > 详细

js ie浏览器下的选中操作

时间:2014-02-28 10:26:11      阅读:606      评论:0      收藏:0      [点我收藏+]

 

最近在学习jquery  好多英文网站,制作一个网站的副本,可以主动地学习。好像给自己的网站添加一个小词典,就像沪江小d那样。

js试了好几种方法 实在不行,网上搜索了下 ,用到了浏览器开发。本篇文章只涉及获取选中文本,离我的想法 还有一定距离。

获取选中文本仅限ie

原文http://msdn.microsoft.com/en-us/library/ie/ms535872(v=vs.85).aspx

bubuko.com,布布扣
<html>
<head>
<script type="text/javascript">
function selText()
{
document.getElementById("myText").select()
}
</script>
</head>


<button onclick="myFunction()">anniu </button>
<form>的jQuery easyui的框架,可帮助您轻松建立自己的网页。

easyui的是基于jQuery的用户界面插件的集合。
easyui的规定,建设现代,互动,JavaScript应用程序必不可少的功能。
使用easyui的你不需要写很多的javascript代码,你通常通过编写一些HTML标记定义了用户界面。
完整的框架,对HTML5的网页。
easyui的节省您的时间和规模,同时发展自己的产品。
easyui的是很容易的,但功能强大。
<input size="25" type="text" id="myText" value="选定我吧!">
<input type="button" value="选择文本" onclick="selText()"> 
</form>
 <script>
  var coll = document.all.tags("button");
  if (coll != null && coll.length > 0) {
    var rng = coll[0].createTextRange();
    rng.text = "Clicked";
  }
function myFunction()
{
var myCollection;
myCollection = document.selection.createRangeCollection();
alert( myCollection.item(0).text );
}
</script><body>

</html>
bubuko.com,布布扣

按照选取改变元素

bubuko.com,布布扣
 var coll = document.all.tags("button");
  if (coll != null && coll.length > 0) {
    var rng = coll[0].createTextRange();
    rng.text = "Clicked";
  }
bubuko.com,布布扣

弹出选中内容

bubuko.com,布布扣
function myFunction()
{
var myCollection;
myCollection = document.selection.createRangeCollection();
alert( myCollection.item(0).text );
bubuko.com,布布扣

产生事件

bubuko.com,布布扣
<!DOCTYPE html>
<html>
<body>

<p>点击这个按钮,来调用带参数的函数。</p>
<script type="text/javascript">
function AddLink()
{
    //identify selected text
    var sText = document.selection.createRange();
    if (sText.text != "")
    {
      //create link
      document.execCommand("CreateLink");
      //change the color to indicate success
      if (sText.parentElement().tagName == "A")
      {
        sText.execCommand("ForeColor",false,"#FF0033");
      }
    }
    else
    {
        alert("Please select some text!");
    }   
}
</script>
<p unselectable="on">Select any portion of the following blue text, such as &quot;My 
favorite Web site&quot;. Click the button to turn the selected text into a link. </p>
<p style="color= #3366CC">My favorite Web site is worth clicking on. Don‘t forget 
to check out my favorite music group!</p>
<button onclick="AddLink()" unselectable="on">Click to add link</button>

<button onclick="myFunction(‘Bill Gates‘,‘CEO‘)">点击这里</button>

<script>
function myFunction(name,job)
{
alert("Welcome " + name + ", the " + job);
}
</script>

</body>
</html>
bubuko.com,布布扣

这个例子可以给选中 文本 添加超链接  

我感觉 好像把IE变成了  编辑器。

至于这个 用法 我觉得给 网站添加 划词 维基百科很酷

我也是初学者   不要留言问题   我只是搬运工 ,详细内容

http://msdn.microsoft.com/en-us/library/ie/ms535872(v=vs.85).aspx

js ie浏览器下的选中操作,布布扣,bubuko.com

js ie浏览器下的选中操作

原文:http://www.cnblogs.com/majin/p/3572019.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!