简体   繁体   中英

javascript/jQuery: Adding linebreak in title — works in IE9, but not in IE8

I'm trying the following to add a linebreak in the title attribute.

<p id="test" title="1|2">test</p>


 var lineBreak = $("<div>&#10</div>").html();

 $("#test").attr("title", $("#test").attr("title").replace("|", lineBreak));

The tooltip result in IE9 is

1
2

in IE8 the result is

12

Is there a chance to fix this for IE8? I really need this way and no custom tooltip etc.

Try it @ jsfiddle: http://jsfiddle.net/8ZCdb/

Try this:

$("#test").attr("title", $("#test").attr("title").replace("|", "\n"));

\\n is a new line operator in plain text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM