admin管理员组

文章数量:1289384

I'm trying to set a button value to be « (or ») via JavaScript with the following code:

document.getElementById('hideButton').value='«';

This just sets the button text to « rather than «.

The HTML markup works fine (i.e. <input type="button" value="&laquo;">) giving the double left arrow quote on the button face.

Is there some special way of escaping the ampersand code in JavaScript?

Thanks,

FM

I'm trying to set a button value to be « (or ») via JavaScript with the following code:

document.getElementById('hideButton').value='&laquo;';

This just sets the button text to &laquo; rather than «.

The HTML markup works fine (i.e. <input type="button" value="&laquo;">) giving the double left arrow quote on the button face.

Is there some special way of escaping the ampersand code in JavaScript?

Thanks,

FM

Share Improve this question edited Mar 27, 2014 at 10:19 niksvp 5,5632 gold badges27 silver badges43 bronze badges asked Mar 27, 2014 at 10:15 Fat MonkFat Monk 2,2651 gold badge30 silver badges73 bronze badges 2
  • Sorry, that was a typo in the question... I've added the extra ; in the question but it was already in my code. – Fat Monk Commented Mar 27, 2014 at 10:19
  • you want to set some text for button face? – Savaratkar Commented Mar 27, 2014 at 10:23
Add a ment  | 

3 Answers 3

Reset to default 10

here just convert to UTF it should work.

document.getElementById('hideButton').value='\u00AB';
document.getElementById('otherButton').value='\u00BB';

here a link to convert special text

couldn't you just do this?

document.getElementById("hideButton").value = "«";

Sorry I would have just mented, but haven't got enough rep yet.

Alternatively, use the unicode \u00AB

http://jsfiddle/s53FH/

you could use the -element instead

<button id="hideButton"> </button>
<script>
    document.getElementById('hideButton').innerHTML='&laquo;';
</script>

http://jsfiddle/6m3zz/

本文标签: htmlSetting a button value to contain an ampersand coded character via JavaScriptStack Overflow