Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript에서 길고 깨지지 않는 단어를 깨고 다음 줄로 줄 바꿈하는 방법은 무엇입니까?


wordWrap 사용 긴 단어가 끊어지고 다음 줄로 줄 바꿈되도록 JavaScript의 속성을 사용합니다.

예시

다음을 실행하여 wordWrap 작업 방법을 배울 수 있습니다. 속성 -

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            width: 150px;
            height: 150px;
            background-color: lightblue;
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <button onclick = "display()">Set</button>

      <div id = "box">
         ThisisDemoText.ThisisDemoText.ThisisDemoText.ThisisDemoText.Thisis DemoText.ThisisDemoText.
      </div>

      <script>
         function display() {
            document.getElementById("box").style.wordWrap = "break-word";
         }
      </script>
   </body>
</html>