如何从页面加载时默认进入的选定文本中删除文本选择? [英] How to remove text selection from selected text which is coming by default on page load?

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

问题描述

当我们刷新或重新加载页面时,当您点击下面的图片部分时,您可以在圈子的中间看到选定的文本:


  1. 讨论目标&关注

  2. 现金流量分析

  3. 税务分析...



  4. 依此类推。

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



    选定的文本仅在第一次点击时发生 - 当您再次点击这些图片部分,您将看不到所选文字。所以我想从第一次尝试的文本中删除选择。



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

      / * ----------单击时的文本更改 - 我们的流程页面--------------- * / 
    var上一张;
    var IdAry = ['slide1','slide2','slide3','slide5','slide8','slide9','slide12','slide13','slide14','slide15','slide16 ];
    window.onload = function(){
    for(var zxc0 = 0; zxc0 var el = document.getElementById(IdAry [zxc0]);
    if(el){
    setUpHandler(el);
    el.onmouseover = function(){
    $(this).addClass(hover);

    el.onmouseout = function(){
    $(this).removeClass(hover);




    函数setUpHandler(el){
    / * ---------这是用来添加(),/ b $ b $(#+ IdAry.join(,#))。click(function(){
    $(this).addClass(selected);
    $(#graphics .selected)。not(this).removeClass(selected);
    })
    / * ---------这会将show hide类添加到它的跨度,反之亦然------- * /
    $(#+ IdAry.join(, (),
    函数(){
    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
    }

    我只想

    要查看选定文本的图片:



    解决方案

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

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


    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

    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.

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

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

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

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