Alerting Special Characters using jQuery/JavaScript

后端 未结 3 900
陌清茗
陌清茗 2021-02-08 03:08

How do i display a string with Special Characters like € in a Javascript/jQuery alert?

eg: I want to display a message box with \"The Price is €10\"

But whe

相关标签:
3条回答
  • 2021-02-08 03:47

    Use this as the alert. Works fine for me.

    alert(' The Price is \u20AC 10');
    

    The description is here : http://leftlogic.com/projects/entity-lookup/

    0 讨论(0)
  • 2021-02-08 04:00

    The native alert method does not decode HTML encoded entities.

    But browsers do while rendering HTML. One hack is to create a HTML element with the specific text as its innerHTML (so it does the character processing), then get back its text property and alerting it out.

    function alertSpecial(msg) {
        msg = $('<span/>').html(msg).text();
        alert(msg);
    }
    alertSpecial('The Price is &euro;10');
    

    This will work for all &xxx characters that the browser can display, without needing to find out the character code for each special character you may want to use.

    0 讨论(0)
  • 2021-02-08 04:04

    Check :

    alert("The Price is \u20AC 10");
    

    http://jsfiddle.net/Nseum/

    Unicode Character 'EURO SIGN' (U+20AC)

    0 讨论(0)
提交回复
热议问题