BBCode Tabelle
Verfasst: So 29. Nov 2015, 13:07
BBCode für eine Tabelle:
Bei BBCode-Benutzung fügst du das ein
Code: Alles auswählen
[table]{TEXT}[/table]
Code: Alles auswählen
<script type="text/javascript">
//<![CDATA[
function tableposting(text) {
if (typeof(text) == "string") {
text = text.replace(/<table(.*?)>/ig, "<table class='posttable'>");
text = text.replace(/<th(.*?)>/ig, "<th>");
text = text.replace(/<tr(.*?)>/ig, "<tr>");
text = text.replace(/<td(.*?)>/ig, "<td>");
text = text.replace(/<thead(.*?)>/ig, "<thead>");
text = text.replace(/<tfoot(.*?)>/ig, "<tfoot>");
text = text.replace(/<\/th>/ig, "</th>");
text = text.replace(/<\/tr>/ig, "</tr>");
text = text.replace(/<\/td>/ig, "</td>");
text = text.replace(/<\/thead>/ig, "</thead>");
text = text.replace(/<\/tfoot>/ig, "</tfoot>");
text = text.replace(/<\/table>/ig, "</table>");
text = text.replace(/<br \/>/ig, "");
}
return text;
}
document.write(tableposting('{TEXT}'));
css = '.posttable {border-collapse:collapse;width:96%;margin:2%;} .posttable th{padding:4px;border:1px solid black;background:lightblue;} .posttable tr:nth-child(odd){background-color:beige;} .posttable tr:nth-child(even){background-color:lightgrey;} .posttable td{padding:4px;vertical-align:middle;border:1px solid black;}',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
//]]>
</script>
Code: Alles auswählen
<table>
<tr><td colspan="2">Spalte 1</td><td>Spalte 2</td><td>Spalte 3</td></tr>
<tr><td>Spalte 1</td><td>Spalte 2</td><td>Spalte 3</td></tr>
<tr><td>Spalte 1</td><td>Spalte 2</td><td>Spalte 3</td></tr>
</table>