1

I'm receiving some HTML with an arbitrary number of tags that I need to truncate in order to fit within 25 characters, however I don't want to leave any open tags.

For example, if I receive blah blah blah <a href="#">supercalifragilistic</a> I need to truncate it to something like blah blah blah <a href="#">superc...</a> rather than blah blah blah <a href="#">supercal...

My best thoughts right now are to use javascript to strip and then reapply the tags after truncation, or to put it all in a div and hide overflow. Not sure what the best option is or if there's an even simpler one.

Thanks!

4

2 回答 2

0

I would start off with userInput.length to return how many characters you actually received.

于 2013-03-30T19:50:53.567 回答
0

I ended up using this JQuery plugin: http://thepugautomatic.com/octopress/2008/02/jquery-html-truncate/

Had to edit the code a little bit to get it to do what I want, but it works. Unfortunately it's a little slower than I'd prefer, but still good for many cases.

于 2013-04-03T20:20:31.507 回答