简体   繁体   English

如何从页面加载时默认出现的所选文本中删除文本选择?

[英]How to remove text selection from selected text which is coming by default on page load?

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. Discuss Goals & Concern 讨论目标与关注
  2. Cash Flow Analysis 现金流量分析
  3. Tax Analysis... 税务分析......

And so on. 等等。

Example: http://ivyfa.advisorproducts.com/financial-planning-process 示例: 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. 所以我想在第一次尝试时从文本中删除选择。

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. 下面是我正在使用的JS代码 - 我认为问题出在ChangeText()函数中。

/*----------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
}

I only want to remove the selected text from the text in the middle when you click on different-2 image tag. 我只想在单击不同的2图像标记时从中间的文本中删除所选文本。

Image to view selected text: 用于查看所选文本的图像:

图像以查看所选文本

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM