我不知道PHP,我想在PHP中实现一个解决方案,而不是通过JS来输出没有解决方案的行标题。
产出:
<table class="rls">
<tr class="res_g_0">
<td class="res-type">
<h3>Wide 16:10 (5K, 4K, HD):</h3>
</td>
<td>
<ul class="list-inline">
<li class="res_1280x800">
<a href=""><strong>1280x800</strong></a>
</li>
<li class="res_1440x900">
<a href=""><strong>1440x900</strong></a>
</li>
</ul>
</td>
</tr>
<!--The class="res_g_1" is generated, but don't have any available resolutions. I remove it from DOM with JS from below."-->
<tr class="res_g_1">
<td class="res-type">
<h3>Mobile (iPhone X):</h3>
</td>
<td>
<ul class="list-inline">
</ul>
<div data-target=".res_g_1" class="not_found_res"></div>
</td>
</tr>
<!--The end of a group resolution without resolutions"-->
<tr class="res_g_2">
<td class="res-type">
<h3>Mobile (Android):</h3>
</td>
<td>
<ul class="list-inline">
<li class="res_480x854">
<a href=""><strong>480x854</strong></a>
</li>
<li class="res_1080x1920">
<a href=""><strong>1080x1920 HD</strong></a>
</li>
</ul>
</td>
</tr>
<script>
var resolution_list = {
init: function () {
if ($('.not_found_res').length) {
$('.not_found_res').each(function () {
$($(this).data('target')).remove();
})
}
}
}
resolution_list.init();
</script>
下面的代码正在生成上面的HTML代码:(在这里,我想在PHP中放置一个if语句或任何东西来不输出没有任何分辨率的决议组)
<table class="rls">
<?php $i = 0; ?>
<?php foreach ($resolutions as $type => $group) { ?>
<tr class="res_g_<?= $i ?>">
<td class="res-type">
<h3><?=$type?>:</h3>
</td>
<td>
<ul class="list-inline">
<?php $found = false; ?>
<?php foreach ($group as $res) { ?>
<?php if ($res->resolution_width > $wallpaper->wallpaper_width || $res->resolution_height > $wallpaper->wallpaper_height) continue; $found = true; ?>
<?php $template = 'wallpaper_preview' ?>
<li class="res_<?= $res->resolution_width . 'x' . $res->resolution_height ?>">
<a href="<?= $this->route_links->build_link($template, $search_replace + array('{R_WIDTH}' => $res->resolution_width, '{R_HEIGHT}' => $res->resolution_height)); ?>"><strong><?= $res->resolution_name; ?></strong></a>
</li>
<?php } ?>
</ul>
<?php if (!$found) { ?>
<div data-target=".res_g_<?= $i ?>" class="not_found_res"> </div>
<?php } ?>
</td>
</tr>
<?php $i++; ?>
<?php } ?>
</table>
那么,我如何在PHP中有一个条件来不输出没有可用分辨率的组呢?
发布于 2018-06-15 10:40:52
你可以IF
条件就在代码之后<?php foreach ($group as $res) { ?>
比如:<?php foreach ($group as $res) { if(<YOUR_RESOLUTION_CONDITION>) {?>
别忘了关闭花括号
https://stackoverflow.com/questions/-100004935
复制相似问题