разделить на колонки элементы
есть много таблиц, генерируются динамически, нужно разделить на две колонки, пробую обернуть в div, но не получается.
<script>
$('table:eq(2)').append('</div><div class="2">');
</script>
<table> <tr> <td></td><td></td> </tr> </table> <table> <tr> <td></td><td></td> </tr> </table> <table> <tr> <td></td><td></td> </tr> </table> <table> <tr> <td></td><td></td> </tr> </table> |
Цитата:
Цитата:
|
Цитата:
Цитата:
<!DOCTYPE html>
<html ng-app>
<head>
<script src='http://code.jquery.com/jquery-latest.js'></script>
<!--
<script src="http://code.angularjs.org/1.1.4/angular.min.js"></script>
<link rel='stylesheet type=text/css href=tmp.css' />
-->
<style type='text/css'>
.right {
float: right;
}
</style>
<script type='text/javascript'>
$(function(){
$('table:even').wrap('<div class="right"></div>');
});
</script>
</head>
<body>
<table border='1'>
<tr>
<td>0</td><td>0</td>
</tr>
</table>
<table border='1'>
<tr>
<td>1</td><td>1</td>
</tr>
</table>
<table border='1'>
<tr>
<td>2</td><td>2</td>
</tr>
</table>
<table border='1'>
<tr>
<td>3</td><td>3</td>
</tr>
</table>
</body>
</html>
|
спасибо большое, интересный вариант. а на javascript (без подключения библиотек) есть какое-то решение ?
|
Цитата:
<html>
<head>
<style>
.right {
float: right;
}
</style>
</head>
<body>
<table border='1'>
<tr>
<td>0</td><td>0</td>
</tr>
</table>
<table border='1'>
<tr>
<td>1</td><td>1</td>
</tr>
</table>
<table border='1'>
<tr>
<td>2</td><td>2</td>
</tr>
</table>
<table border='1'>
<tr>
<td>3</td><td>3</td>
</tr>
</table>
<script>
c=0
;[].forEach.call(document.querySelectorAll("table"), function(el){if(c++%2==0) el.className="right"})
</script>
</body>
</html>
? |
Цитата:
|
Цитата:
Вот вариант вообще без скриптов. :)
<!DOCTYPE html>
<html ng-app>
<head>
<!--
<script src='http://code.jquery.com/jquery-latest.js'></script>
<script src="http://code.angularjs.org/1.1.4/angular.min.js"></script>
<link rel='stylesheet type=text/css href=tmp.css' />
-->
<style type='text/css'>
table:nth-child(odd) {
float: right;
}
</style>
<script type='text/javascript'>
</script>
</head>
<body>
<table border='1'>
<tr>
<td>0</td><td>0</td>
</tr>
</table>
<table border='1'>
<tr>
<td>1</td><td>1</td>
</tr>
</table>
<table border='1'>
<tr>
<td>2</td><td>2</td>
</tr>
</table>
<table border='1'>
<tr>
<td>3</td><td>3</td>
</tr>
</table>
</body>
</html>
Правда и оборачивания ДИВами тут нет... |
| Часовой пояс GMT +3, время: 16:42. |