满足我的控制器的要求:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AutoLoadDiv extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('ngoding/AutoLoad');
}
public function getData() {
$this->load->library('table');
$err = file_get_contents("application\logs\log.php");
$filestr = preg_replace(array('/(^|\R)ERROR\s*-\s*/', '/(^|\R)(.*?)\s*-->\s*/'), array('$1', '$1$2 '), $err);
$arraySpacing = nl2br($filestr);
$arr = explode("\n", $arraySpacing);
$output = '<table style="tr:nth-child(even){background-color#FFF;} tr:nth-child(odd){background-color:#CCC;}", border="1px solid #dddddd;" >';
for ($i = count($arr)-1; $i >= 0; $i--) {
$output.="<tr><td>$arr[$i]</td></tr>";
}
$output.="</table>";
echo $output;
}
}
我在每行不同的行中添加颜色背景时遇到问题,我找到了答案,但是没有用,答案是在tr:nth-child(even)
和tr:nth-child(odd)
内添加代码,如何添加tr:nth-child(even)
和标签中的tr:nth-child(odd)
?
答案 0 :(得分:1)
添加另一个包含样式表的$output
,例如:
$output = '<style> tr:nth-child(even){background-color#FFF;} tr:nth-child(odd){background-color:#CCC;} </style>';
$output .= '<table border="1px solid #dddddd;" >';