This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Zeilenumbruch in td
#1
Hallo Zusammen,
ich erzeuge die Zellen einer Tabelle dynamisch und benötige in dem Zelleninhalt an bestimmten Stellen einen Zeilenumbruch. Hab's mit br, /n /r/n probiert, geht aber alles nicht.

hier der Quelltext (Button oben links drücken):

[font=Consolas, "Courier New", monospace]<html>
<head>
<title>Umbruchtest</title>
<script type="text/javascript">
 
function addRow(tableID){
  let tableRef = document.getElementById('mytable-js');

    // Füge am Ende der Tabelle eine neue Zeile an
    let newRow = tableRef.insertRow(-1);

    // Erstelle in der Zeile eine Zelle am Index 0
    let newCell = newRow.insertCell(0);

    var str =  "java-text:<br />" + "\r\n" + " hier sollte Zeile2 sein";

    let newText = document.createTextNode(str);
    newCell.appendChild(newText);
}
</script>
</head>
<body>
<button onclick="addRow('mytable-js');">test</button>

<table  border=”2″  id="mytable-js">
                 
  <thead>
      <tr>
          <td>Beschreibung </td>
       </tr>
   </thead>
   <tbody>

       <tr>
          <td>html-text<br />Mit Zeilenumbruch (so soll es aussehen) </td>
       </tr>

   </tbody>
</table>

</body>
</html>[/font]
Zitieren
#2
Das habe ich dir im anderen Forum auch schon geschrieben


Was steht den da ???
Zitat:createTextNode


Das macht das ,was auch da steht.
Du musst HTML erstellen.
<script>
function addRow(tableID){
    let tableRef = document.getElementById('mytable-js');
    let newRow = tableRef.insertRow(-1);
    let newCell = newRow.insertCell(0);
    newText=newCell.innerHTML= "java-text:<br> hier sollte Zeile2 sein";
    newCell.appendChild(newText);
}
</script>


PS:

Denk dran das Crossposting in vielen Foren nicht erlaubt ist  und deswegen die Beiträge gesperrt werden können.
Als Lösung markieren Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste