简体   繁体   English

如何在html中打破长词?

[英]how to break the long word in html?

I'm creating list dynamically in javascript. 我正在用javascript动态创建列表。 I want to break the long word in as dot dot dot(.....). 我想将长字打乱为点点点(.....)。 For example, if the word is "Software life cycle development" I want to change it as "Software life cycl....". 例如,如果单词是“软件生命周期开发”,我想将其更改为“软件生命周期...”。

And I used "WORD-BREAK:BREAK-ALL;white-space:normal;" 然后我使用“ WORD-BREAK:BREAK-ALL; white-space:normal;” My current output is: 我当前的输出是:

Software life cycle development. 软件生命周期开发。

Can anyone tell, how to fix this? 谁能说出来,如何解决呢? thanks in advance. 提前致谢。

  var parent = document.getElementById('searchlistview');
var listItem = document.createElement('li');
listItem.setAttribute('id', 'listitem_' + listId);
listItem.setAttribute('data-icon', 'false');
listItem.innerHTML = "<img src=" + imagesrc + " class='ui-li-icon ui-li-has-icon'></img>
<a target='_black' data-role='button' href='#' id=" + listId + " name= " + url + " data-theme ='c' rel='external' 
data-inline='true' style='margin-left:0em; WORD-BREAK:BREAK-ALL;white-space:normal; ' >" + searchName + "<p style='margin-top:1px;margin-left:1px;'>
File size: " + fileSize + "</p></a>";
parent.appendChild(listItem);

You can try this css 你可以试试这个CSS

text-overflow:ellipsis;

It would put ... when the text overflow. 当文本溢出时,它将放... see this page for your reference. 请参阅此页面以供参考。

see if css ellipsis can help you. 看看CSS省略号能否为您提供帮助。 You can find more details at 您可以在以下位置找到更多详细信息

http://www.w3schools.com/cssref/css3_pr_text-overflow.asp http://www.w3schools.com/cssref/css3_pr_text-overflow.asp

http://mattsnider.com/css/css-string-truncation-with-ellipsis/ http://mattsnider.com/css/css-string-truncation-with-ellipsis/

Try: 尝试:

function wbr(str, num) { 
  return str.replace(RegExp("(\\w{" + num + "})(\\w)", "g"), function(all,text,char){
    return text + "<wbr>" + char;
  });
}

Source: http://ejohn.org/blog/injecting-word-breaks-with-javascript/ 资料来源: http : //ejohn.org/blog/injecting-word-breaks-with-javascript/

style="text-overflow: ellipsis;"

将解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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