How to print a pound “£” in html file?

前端 未结 7 1147
再見小時候
再見小時候 2021-01-21 06:43

i am trying to display a pound sign in my html page.i want to display it through a variable because i am getting the values of sign from an xml file.

Here is Code:

相关标签:
7条回答
  • 2021-01-21 07:04

    To print a pound symbol, simply ... print the pound symbol:

    var sign = '£';
    
    $('#monthly_Amt').text(sign + monthlypayment);
    

    Or, if that's somehow uncomfortable:

    var sign = "\u00A3";
    
    $('#monthly_Amt').text(sign + monthlypayment);  
    

    Or, with the quotes:

    $('#monthly_Amt').text("'" + sign + "'" + monthlypayment);  
    

    Demo

    Update

    It seems that the "variable" actually comes from an HTML element, but \x00A3 only works in string literals.

    This HTML fixes it:

    <div id="currencySign">&pound;</div>
    

    Demo

    0 讨论(0)
  • 2021-01-21 07:09

    May be you have to look into it.

    <div id="divResponse">
    </div>
    
    $(document).ready(function () {
    var sign = "\u00A3"
    var monthlypayment = "5000"
    $('#divResponse').text(sign+monthlypayment);
    });
    

    here is the fiddle link : poundExampleJSFiddle

    If this is helpful to you, please mark it as helpful.

    Thanks

    0 讨论(0)
  • 2021-01-21 07:11

    It is:

    &pound; 
    

    or

    &#163;
    

    You can check other encodings here:

    http://www.w3schools.com/html/html_entities.asp

    And here is a demo on how to do it: Online Demo

    var sign = "&pound;";
    $('#demo').html(sign+124.5);
    
    0 讨论(0)
  • 2021-01-21 07:12

    You can use \u00A3 ...

    Demo

    Alternatively you can use entity name as &pound; or entity number as &#163; as well but you need to use .html() and NOT .text()

    And use var and not Var


    As you commented, I see you are getting more troubles with this, if you want you can accomplish this easily with CSS like

    #monthly_amt:before {
        content: "'£'"; /* Or you can use \00a3 instead of £ */
    }
    

    And your jQuery will be

    var monthlypayment = 1000;
    $('#monthly_amt').text(monthlypayment);
    

    And if the element is dynamically generated, you can get rid of it using .remove()

    Demo 2

    0 讨论(0)
  • 2021-01-21 07:17

    Try this one,

    £   &pound; &#163;  &#xA3;  Pound Sterling
    

    See this Link

         http://webdesign.about.com/od/localization/l/blhtmlcodes-cur.htm
    
    0 讨论(0)
  • 2021-01-21 07:25

    Try using:

    var sign = '&#163;'
    $('#monthly_Amt').html("\'"+sign+"\'"+monthlypayment);
    

    For the £ sign use: &#163; (ASCII Code)

    http://jsfiddle.net/seckela/7gjF5/

    EDIT: Using .text() will render the literal text, .html interprets it as an HTML element and will render special ASCII Characters using the ASCII codes.

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