var txt = 'Some texts, html tags & all values i can enter through text box';
txt= txt.substring(0,255)+'...';
Run Code Online (Sandbox Code Playgroud)
我可以使用 css 做这件事吗?
我的问题是,如果txt包含 HTML 标签,则在执行子字符串后,结束标签会丢失并且会中断。
但为此你应该设置width元素 -
试试这个 CSS -
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
display: inline-block;
Run Code Online (Sandbox Code Playgroud)