admin管理员组

文章数量:1418136

If I just put in XUL file

<label value="&#176;C"/> 

it works fine. However, I need to assing &#176; value to that label element and it doesn't show degree symbol, instead literal value.

UPD sorry guys, I just missed couple words here - it doesn't work from within javascript - if I assign mylablel.value = degree + "&#176;" - this will show literal value.

It does show degree symbol only if I put above manually in XUL file.

If I just put in XUL file

<label value="&#176;C"/> 

it works fine. However, I need to assing &#176; value to that label element and it doesn't show degree symbol, instead literal value.

UPD sorry guys, I just missed couple words here - it doesn't work from within javascript - if I assign mylablel.value = degree + "&#176;" - this will show literal value.

It does show degree symbol only if I put above manually in XUL file.

Share Improve this question edited May 9, 2010 at 15:13 Ms2ger 16k6 gold badges40 silver badges36 bronze badges asked May 9, 2010 at 9:08 PabloPablo 29.6k37 gold badges135 silver badges226 bronze badges 3
  • Re your update: Strange. The only explanation I have for that behaviour is that &#176; gets automatically converted to &amp;#176; along the way. Could that be? – Pekka Commented May 9, 2010 at 10:06
  • @Pekka: it's possible, but how to avoid it? – Pablo Commented May 9, 2010 at 10:17
  • impossible to tell without seeing more source... And as I said, I don't know about XUL and what might be done there automatically. Anyway, I can't see anything in the Mozilla Docs explaining the behaviour. Very odd. – Pekka Commented May 9, 2010 at 10:28
Add a ment  | 

3 Answers 3

Reset to default 3

What happens when you use a JavaScript escape, like "\u00B0C", instead of "&#176;C"?

Or when using mylabel.innerHTML instead of mylabel.value? (According to MDC, this should be possible.)

EDIT: you can convert those entities to JavaScript escapes using the Unicode Code Converter.

This makes sense to me. When you express the entity in an attribute value within XML markup, the XML parser interpolates the entity reference and then sets the label value to the result. From Javascript, however, there's no XML parser to do that work for you, and in fact life would be pretty nasty if there were! Note that when you set the value attribute (from Javascript) of an <input type='text'> element, you don't have to worry about having to escape XML entities (or even angle brackets, for that matter). However, you do have to worry about XML entities when you're setting the "value" attribute within XML markup.

Another way to think about it is this: XML entity notation is XML syntax, not Javascript syntax. In Javascript, you can produce special characters using 16-bit Unicode escape sequences, which look like \u followed by a four-digit hex constant. As noted in Marcel Korpel's answer, if you know what Unicode value is produced by the XML entity, then you should be able to use that directly from Javascript. In this case, you could use "\u00B0".

This way it will not work ,can you convert it to be like this

<label>&#176;C</label> 

本文标签: javascripthtml entity is not renderedStack Overflow