admin管理员组文章数量:1313112
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:
var sign = $('#currencySign').text();
$('#monthly_Amt').text("\'"+sign+"\'"+monthlypayment);
<div id="monthly_amt"></div>
<div id="currencySign">\u00A3</div>
and the out put is
'\u00A3'450.33
and i want it as £450.33
Fiddle
How can I fix this?
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:
var sign = $('#currencySign').text();
$('#monthly_Amt').text("\'"+sign+"\'"+monthlypayment);
<div id="monthly_amt"></div>
<div id="currencySign">\u00A3</div>
and the out put is
'\u00A3'450.33
and i want it as £450.33
Fiddle
How can I fix this?
Share Improve this question edited Jun 12, 2014 at 6:29 Ja͢ck 174k39 gold badges266 silver badges314 bronze badges asked Jun 12, 2014 at 5:20 user2142786user2142786 1,48210 gold badges43 silver badges79 bronze badges 5- 1 you have to use £ – Pranav Commented Jun 12, 2014 at 5:23
- I've found the issue and updated my answer accordingly. – Ja͢ck Commented Jun 12, 2014 at 6:16
- @Jack retract the close vote – Mr. Alien Commented Jun 12, 2014 at 6:33
- @Mr.Alien oooh shiny new feature! – Ja͢ck Commented Jun 12, 2014 at 6:39
- @Jack they provided that way back, am using that since 1-2 months (I guess) – Mr. Alien Commented Jun 12, 2014 at 6:42
7 Answers
Reset to default 5You can use \u00A3
...
Demo
Alternatively you can use entity name as £
or entity number as £
as well but you need to use .html()
and NOT .text()
And use var
and not Var
As you mented, I see you are getting more troubles with this, if you want you can acplish 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
It is:
£
or
£
You can check other encodings here:
http://www.w3schools./html/html_entities.asp
And here is a demo on how to do it: Online Demo
var sign = "£";
$('#demo').html(sign+124.5);
To print a pound symbol, simply ... print the pound symbol:
var sign = '£';
$('#monthly_Amt').text(sign + monthlypayment);
Or, if that's somehow unfortable:
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 es from an HTML element, but \x00A3
only works in string literals.
This HTML fixes it:
<div id="currencySign">£</div>
Demo
Try this one,
£ £ £ £ Pound Sterling
See this Link
http://webdesign.about./od/localization/l/blhtmlcodes-cur.htm
Try using:
var sign = '£'
$('#monthly_Amt').html("\'"+sign+"\'"+monthlypayment);
For the £ sign use: £ (ASCII Code)
http://jsfiddle/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.
Use £
;
$(this).text('&#163;');
If you try this and it does not work, just change the jQuery methods,
$(this).html('£');
This always work in all contexts...
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
本文标签: javascriptHow to print a pound quot163quot in html fileStack Overflow
版权声明:本文标题:javascript - How to print a pound "£" in html file? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741933536a2405715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论