javascript - 更改屏幕宽度时更改变量(例如横向到纵向)
问题描述
我正在将数据库中的消息显示到列中。在 iPhone(屏幕尺寸 375 X 812 像素)上查看时,它可以工作。然而,当手机变成横向(812 x375)时,列的数量不会改变这里是代码:
<div class="content">
<table class="table1" width="98%">
<?php $count = '0';
if ($screenwidth < 481){$max_columns =3;}else {
$max_columns = 4;}
do {
if ($count < $max_columns){
if ($count == 0){
echo "<tr>";
}?>
<td align="center" class="td1">
<div> <php echo $message ?>
</div>
</td>
<?php } else {
$count = 0;
echo "</tr><tr>";?>
<td align="center" class="td1">
<div ><?php echo $message;</div>
<?php echo "</td>";?>
<?php } $count++; }
while($row_RS_Search = $RS_Search2->fetch() );
echo "</tr>"; ?>
</table></div>
然后我试图检索屏幕宽度,如下所示:
<?php
$clientProps=array('screen.width','screen.height','window.innerWidth','window.innerHeight',
'window.outerWidth',);
if(! isset($_POST['screenheight'])){
echo "Loading...<form method='POST' id='data' style='display:none'>";
foreach($clientProps as $p) { //create hidden form
echo "<input type='text' id='".str_replace('.','',$p)."' name='".str_replace('.','',$p)."'>";
}
echo "<input type='submit'></form>";
echo "<script>";
foreach($clientProps as $p) { //populate hidden form with screen/window info
echo "document.getElementById('" . str_replace('.','',$p) . "').value = $p;";
}
echo "document.forms.namedItem('data').submit();"; //submit form
echo "</script>";
}else{
foreach($clientProps as $p) { //create output table
}
$screenwidth = $_POST['screenwidth'] ;
$screenheight =$_POST['screenheight'];
}
?>
这适用于加载页面,但是当屏幕转动时,屏幕不会改变。我知道这可能是 php 脚本,但是我对 AJAX 或 Java 不是很好,任何帮助将不胜感激
解决方案
推荐阅读
- python - Pandas 按范围分组
- redis - Redisson 不存储在 Redis 中?
- c++ - 在 C++ 中返回和打印字符串
- typescript - 如何使用“const”值作为类型?
- javascript - 将一个大整数编码为 base62
- tensorflow - 使用 tf.Session() 时模型未训练
- leaflet - 在传单上突出显示建筑物
- javascript - 为什么我不能在表单输入(子组件)和 React useState Hook(父组件)之间共享信息?
- c++ - 为什么 const rvalue 引用隐式转换为 const 引用?
- android - 从 Nox 模拟器在 ampps localhost 中打开 Wordpress