【发布时间】:2018-10-11 16:38:13
【问题描述】:
我的桌子有问题,我不能使用 Javascript(我知道这会更容易)。我只能使用 HTML、PHP 和 CSS。这是我目前拥有的代码。我需要解决的问题如下:
我可以添加、删除行,也可以使用“contenteditable”编辑它们,但是我的问题是每次添加或删除行时,它都会刷新整个页面.我该如何解决这个问题?
如果有办法使用编辑按钮代替我的可竞争方法。
这是我的代码:
input {
display: block; /* makes one <input> per line */
width: 150px;
}
<?php
if( isset( $_REQUEST["btnadd"]) == "ADD") {
// add 1 to the row counter
if (isset($_REQUEST['count'])) $count = $_REQUEST['count'] + 1;
// set value for first load
else $count = 1;
}
if( isset( $_REQUEST["btnremove"]) == "REMOVE") {
// decrement the row counter
$count = $_REQUEST['count'] - 1;
// set minimum row number
if ($count < 1) $count = 1;
}
?>
<form name="form1">
<table class="table table-bordered table-striped table-hover text-center" align='center'>
<tr>
<th align="center">Name</th>
<th>Start </th>
<th>Size</th>
<th>First Condition</th>
<th>Second Conditon</th>
<th><input type="submit" name="btnadd" id="btnadd" value="ADD" align='center'></th>
</tr>
<?php
// print $count rows
for ($i=1; $i<=$count; $i++) {
echo ' <tr>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
<td> <input type="submit" name="btnremove" id="btnremove" value="REMOVE"></td>
</tr>
';
}
?>
</table>
<input type="hidden" name="count" value="<?php echo $count; ?>">
</form>
【问题讨论】:
-
这正是
input type="submit"应该要做的事情。 PHP 只能对页面服务器端进行更改。你猜对了,唯一的方法就是使用 JavaScript。 -
我刚刚从 更改为按钮,它仍然做同样的事情。你对我接下来可以做什么有什么想法吗?我一直在到处寻找如何在没有 js 的情况下做到这一点:(
-
<button type="submit">s 与<input type="submit">几乎相同...正如@Blazemonger 所暗示的,不幸的是,这不是纯粹使用PHP 和HTML 可以完成的。 “PHP 只能对页面服务器端进行更改”,换句话说,PHPechoes 之后无法更改的任何内容,例如您大声说出来的内容,之后都无法更改。您看到的 PHP 已经echoed,除非您使用 javascript,否则无法更改 :( -
不幸的是,这是有道理的:(谢谢你的解释
-
为什么不能使用 JavaScript?
标签: php html css html-table