Einzelne/doppelte Anführungszeichen dürfen in HTML-Attribut-Werte?

Ich versuche mit Attribut-Wert enthält ein einzelnes Zitat:

var attr_value = "It's not working";
var html = "<label my_attr='" + attr_value + "'>Text</label>";
$('body').html(html);

Allerdings bekomme ich das folgende Ergebnis:

<label working="" not="" s="" my_attr="It">Text</label>

Wie könnte ich dieses Problem beheben ?

Sind Anführungszeichen erlaubt, innerhalb Attribut-Werte ?

InformationsquelleAutor Misha Moroshko | 2010-10-22

Schreibe einen Kommentar