我有一个计数器,根据计数器的内容向表中添加行数。我有一个按钮,每次单击时都会增加计数器,但它只能运行一次。
PHP:
if (isset($_REQUEST['Addmore'])) {
$NoOfUsers++;
<form action="addstudent.php">
<th>
<button type="submit" class="btn btn-default btn-sm spoiler-trigger pull-right" aria-label="Left Align" name="Addmore" title="Add Row">
<span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"> </span>
</button>
</th>
</form>
答案 0 :(得分:0)
<强> PHP 强>
<?php
session_start();
if (isset($_REQUEST['Addmore'])) {
?><button class="btn btn-default"><?php
echo $_SESSION['NoOfUsers'] ? ++$_SESSION['NoOfUsers'] : $_SESSION['NoOfUsers']=1;
?></button><?php
}
或 JavaScript
<button id="counter" class="btn btn-default">0</button>
<script>
$('#counter').on('click',function(){$( this ).html(1 * $( this ).html() + 1)});
</script>