I've currently got a genuinely bizarre issue.
Facebook uses the · symbol liberally. I'm trying to replace it with a regular hypen, but I've got a... strange error.
If I put "·" in my HTML document it displays as "·" on the page. 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 "-". 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. 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("·","-");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.