Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

aus x Zeilen eine Liste machen

Empfohlene Antworten

Veröffentlicht

Hallo,

ich habe in einer Variable aus einer Textarea 3 Zeilen, diese 3 Zeilen möchte ich per Javascript als komplette html Liste ausgeben, also:

aus:

aaa

bbb

ccc

mache:

<ul>

<li>aaa</li>

<li>bbb</li>

<li>ccc</li>

</ul>

Hat da jemand irgendwo einen fertigen Codeblock? ;)

Gruß Jaraz

Einen Codeschnipsel habe ich gerade nicht zur Hand, aber mit der Methode split() des string-Objektes und der Methode write des document-Objektes sollte es gehen.

Mit erster splittest Du den Text über den Zeilenumbruch auf (\n z.B.), das resultierende Array kann dann in einer For-Schleife abgearbeitet werden.

Mit document.write() kannst Du dann den HTML-Code des Tabellenkonstruktes ausgeben.

- Monty


$string = $_POST['textarea'];
$string = str_replace('\n','</li>\n<li>');
$string = "<ul>\n<li>".$string."</li>\n</ul>";
[/PHP]

das sollte gehen....


$string = $_POST['textarea'];
$string = str_replace('\n','</li>\n<li>');
$string = "<ul>\n<li>".$string."</li>\n</ul>";
[/PHP]

das sollte gehen....

Öhm, ich wollte Javascript. ;)

Alles muss man selber machen: :(

[code] strSelection = trim(strSelection); strSelection = strSelection.replace(/\r\n/g, "\n"); strSelection = strSelection.replace(/\n/g, "</li>\n<li>"); document.selection.createRange().text = "<ul>\n<li>" + strSelection + "</li>\n</ul>"; function trim(inputString) { if (typeof inputString != "string") return inputString; return inputString //clear leading spaces and empty lines .replace(/^(\s|\n|\r)*((.|\n|\r)*?)(\s|\n|\r)*$/g,"$2") //take consecutive spaces down to one .replace(/(\s(?!(\n|\r))(?=\s))+/g,"") //take consecutive lines breaks down to one .replace(/(\n|\r)+/g,"\n\r") //remove spacing at the beginning of a line .replace(/(\n|\r)\s/g,"$1") //remove spacing at the end of a line .replace(/\s(\n|\r)/g,"$1"); } [/code]

Gruß Jaraz

*gg* VORSICHT

so sachen wie .createRange funktionieren bei weitem nicht in allen Browsern.

Ich kann nachher mal meinen Code raussuchen...sollte da noch was für Cross-Browser haben....

ansonsten...Javascript...ja hast recht...wer lesen kann ist klar im vorteil ^^

*gg* VORSICHT

so sachen wie .createRange funktionieren bei weitem nicht in allen Browsern.

Ich kann nachher mal meinen Code raussuchen...sollte da noch was für Cross-Browser haben....

Ja, das war auch nur der IE Teil der Funktion, den Mozilla Part hatte ich noch nicht angepasst. Der Rest ist bei der Funktion egal, weil es eine Backend Funktion ist und die anderen halt die Liste von Hand tippen müssen. ;)

Wer mit was anderen als IE oder Mozilla surft, kann das aber auch. ;)

Gruß Jaraz

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.