【问题标题】:How to remove highlight from text containing onclick event?如何从包含 onclick 事件的文本中删除突出显示?
【发布时间】:2014-09-22 21:55:27
【问题描述】:

我正在使用在 webView 中为 windows phone 8.1 显示此 html 代码,我猜它使用 IE 11。

<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
    </head>
    <body>
    <p><font size="4">
    <span id="1" onclick=notify(1)>Man this is awkward.</span>
    <span id="2" onclick=notify(2)> Why is everyone so quite today.</span>
    <span id="3" onclick=notify(3)> Oh please someone talk to me.</span>
    <span id="4" onclick=notify(4)> This silence is intimidating.</span>
    <br><br><br><br></font></p><style>

                    body {
                      -webkit-user-select: none;
                         -moz-user-select: -moz-none;
                          -ms-user-select: none;
                              user-select: none;
                    }
                    </style><script>
                    function notify(val)
                    {
                         window.external.notify(val.toString());
                    } 
                    </script></body></html>

但是当我点击任何一行时,整行都会像这样被选中。

我想删除此突出显示。有没有办法做到这一点?

【问题讨论】:

  • 这个页面只能在 IE11 上查看还是在其他移动浏览器上也可以查看?

标签: javascript html internet-explorer windows-phone-8 internet-explorer-10


【解决方案1】:

CSS

outline-style: none; 
-webkit-touch-callout: none;
-webkit-tap-highlight-color: rgba(0,0,0,0);

JavaScript

document.addEventListener("touchstart", function(){}, true);

以及 touchstart 的作用:

$('body').live(
'touchstart', 
function(e){
    if(e.target.localName != 'select'){
        e.preventDefault(); 
    }
}

如果这不起作用,请检查this。希望对您有所帮助。

【讨论】:

  • 你能告诉javascript代码在做什么吗?
  • 不,这不起作用,我会通过链接。
  • @ac-lab 你也可以试试document.getElementById("4").style.webkitTapHighlightColor = "rgba(0,0,0,0)";
  • @ac-lab 哦,请确保您在删除 outline、-webkit-touch-callout: none; 和 -webkit-tap-highlight-color: rgba(0,0,0,0); 的元素上放置了单独的 :hover、:focus 和 :active 样式从。也许它可以解决问题。
猜你喜欢
  • 2011-08-31
  • 1970-01-01
  • 2013-04-19
  • 2018-04-19
  • 2015-05-09
  • 2011-04-13
  • 2020-03-24
  • 2014-07-09
  • 1970-01-01
相关资源
最近更新 更多