如何从默认情况下在页面加载中选择的文本中删除文本选择? [英] How to remove text selection from selected text which is comming by default on page load?

查看:117
本文介绍了如何从默认情况下在页面加载中选择的文本中删除文本选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们重新整理或重新载入网页时,当您点击下面的图片部分时,您可以在圈子中间看到所选文字:

When we refresh or reload the page, you can see a selected text in middle of circle when you click on below image portion:


  1. 讨论目标&关注

  2. 现金流量分析

  3. 税务分析...


$ b b

等等。

And so on.

示例: http://ivyfa.advisorproducts.com/financial-planning-process

所选文字仅在第一次点击时再次单击那些图像部分,您将看不到选定的文本。所以我也想从第一次尝试的文本中删除选择。

The selected text is only coming on the first click - when you click again on those image portions you will not see selected text. So I want to remove the selection from the text on the first attempt too.

我很难解释这个问题。下面是我使用的JS代码 - 我认为问题是在 ChangeText()功能。

It's difficult for me to explain this issue. Below is the JS code I am using - I think the issue is in the ChangeText() functionality.

/*----------Text change on click - Our Process page---------------*/
var prev;
var IdAry = ['slide1', 'slide2', 'slide3', 'slide5', 'slide8', 'slide9', 'slide12', 'slide13', 'slide14', 'slide15', 'slide16'];
window.onload = function() {
  for (var zxc0 = 0; zxc0 < IdAry.length; zxc0++) {
    var el = document.getElementById(IdAry[zxc0]);
    if (el) {
      setUpHandler(el);
      el.onmouseover = function() {
        $(this).addClass("hover");
      }
      el.onmouseout = function() {
        $(this).removeClass("hover");
      }
    }
  }
}
function setUpHandler(el) {
  /*---------This is used to add selected class on clicked id only and remove class selected from rest---------*/
  $("#" + IdAry.join(",#")).click(function() {
    $(this).addClass("selected");
    $("#graphics .selected").not(this).removeClass("selected");
  })
  /*---------This will add show hide class to thier spans and vise versa-------*/
  $("#" + IdAry.join(",#")).click(
    function() {
      changeText(this, "hide", "show");
    },
    function() {
      changeText(this, "show", "hide");
    })
}
function changeText(obj, cl1, cl2) {
  obj.getElementsByTagName('SPAN')[0].className = "hide";
  obj.getElementsByTagName('SPAN')[1].className = "show";
  if (prev && obj !== prev) {
    prev.getElementsByTagName('SPAN')[0].className = "show";
    prev.getElementsByTagName('SPAN')[1].className = "hide";
  }
  prev = obj
}

图片:

提前感谢。

推荐答案

一旦你显示你的控件,你应该清除文本选择;你可以通过调用这个函数(应该是完全跨浏览器)来实现这一点:

You should clear text selection once you display your control; you can do this by calling this function (should be fully cross-browser):

function clearSelection() {
    if (window.getSelection) window.getSelection().removeAllRanges();
    else if (document.selection) document.selection.empty();
}

这篇关于如何从默认情况下在页面加载中选择的文本中删除文本选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆