Is this possible in XHTML: tags in a title-attribu

2019-07-30 12:47发布

I got following code in an XHTML-document and every browser saysit is malformed :(

<a      class="tooltip" 
        title="Um nach einem <b>Datensatz zu suchen</b>, k&ouml;nnen Sie mehrere 
                Suchbegriffe auf einmal eingeben!<br />
                Um <b>Zeilen zu l&ouml;schen</b>, selektieren Sie diese bitte und 
                klicken dann auf <i>'Zeile(n) l&ouml;schen'</i>.<br />
                Um <b>einen Datansatz zu bearbeiten</b>, klicken Sie einfach zweimal 
                auf die Zelle und dann auf <i>'Done'</i>.<br />
                Um <b>eine Zeile hinzuzuf&uuml;gen</b>, klicken Sie auf <i>'Zeile 
                hinzuf&uuml;gen'</i>. Anschlie&szlig;end k&ouml;nnen Sie diese direkt
                editieren"
>
    <img src="img/info.png" width="35px" height="35px" id="fernglas" />
</a>

Now, is it malformed or not? If so, how could I make it right? Thnx in advance

... dg

4条回答
时光不老,我们不散
2楼-- · 2019-07-30 12:58

You would have to entity encode the content within the title attribute. However the browser will not parse the attribute for HTML markup.

查看更多
Root(大扎)
3楼-- · 2019-07-30 13:05

You could reach that effect by using JavaScript, just display div with position absolute etc ;)

查看更多
甜甜的少女心
4楼-- · 2019-07-30 13:06

You can indeed use HTML character entities in the title attribute of a tag. However, you are trying to use HTML tags, which does not appear allowed. You won't be able to use things like bold and italics, but you will be able to add line breaks and some other simple formatting.

查看更多
何必那么认真
5楼-- · 2019-07-30 13:08

I assume you're reading or rendering that title through a script?
If so, just replace every < with &lt; and every > with &gt; and unescape it later.

查看更多
登录 后发表回答