简体   繁体   English

替换·符号

[英]Replacing the · symbol

I've currently got a genuinely bizarre issue. 我目前遇到一个真正奇怪的问题。

Facebook uses the · symbol liberally. Facebook自由使用·符号。 I'm trying to replace it with a regular hypen, but I've got a... strange error. 我正在尝试用常规的hypen代替它,但是我遇到了一个...奇怪的错误。

If I put "·" in my HTML document it displays as "·" on the page. 如果我在HTML文档中输入“·”,则在页面上显示为“·”。 If I put "·" in the document it displays as "·" on the page. 如果我在文档中放入“·”,则在页面上显示为“×”。 If I put "·" in the document is displays as "·" on the page. 如果我在文档中输入“Ô,则会在页面上显示为“ƒ”。 If I put "·" in the document it displays as "ÃÆ'‚·" on the page. 如果我在文档中放入“ÂÃ,·”,它在页面上将显示为“ÃÆ'â⬬šÃ‚·”。 I assume this continues happening. 我认为这继续发生。

I think this is the cause of my issue, but basically I'm wanting to be able to put "·" in a textbox and have Javascript change it to "-". 我认为这是造成我问题的原因,但基本上我希望能够在文本框中输入“·”并将Javascript更改为“-”。 For the sake of completeness here is my full code: 为了完整起见,这是我的完整代码:

<html>
    <body>
        <div id="display"></div><br/>
        <input type=textbox id="text_in"/>
        <input type=submit onclick='replaceDots()'/>

        <script>
            function replaceDots() {
                var text_in = document.getElementById("text_in").value;
                document.getElementById("display").innerHTML = text_in.replace("·","-");    
            }
        </script>
    </body>
</html>

When I put in the · symbol is displays · in the output. 当我输入·符号将在输出中显示·。 Curiously though, if I set text_in in the function to be equal to '·' it displays a hyphen in the output. 但是奇怪的是,如果我在函数中将text_in设置为等于“·”,它将在输出中显示连字符。 This is why I the · error is to blame, though honestly this has me stumped. 这就是为什么我要归咎于错误,尽管老实说,这让我感到难过。

Any ideas? 有任何想法吗?

You need to use the escaped value instead. 您需要改用转义值。 Replace your line with this: 用以下内容替换行:

document.getElementById("display").innerHTML = text_in.replace("&#183;","-");

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

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