我對JS的2個功能方面的數據:如何保存的JavaScript形式
<script>
function inc(elem)
{
elem.value++;
}
function dec(elem)
{
if(elem.value>1)
{
elem.value--;
}
}
</script>
而且這種形式在HTML:
<form method="POST" action= "tameio.php" >
<input type="hidden" value="0" id="counter" name="counter">
<input type = "submit" value = "NextPage" name = "submit" onClick="inc(document.getElementById('counter')); ">
<input type = "submit" value = "PreviousPage" name = "submit" onClick="dec(document.getElementById('counter'));">
</form>
這裏是PHP:
<?php
if(isset($_POST['submit']))
{
echo $_POST['counter'];
if($_POST['submit'] == 'NextPage'){
...
}
}
?>
所以問題是,我點擊NextPage按鈕後,0變爲1,但它沒有存儲在窗體中,所以它再次在html上變爲0。如果我重新點擊它,它會再次發送1。我應該用阿賈克斯嗎?
我想你要找的是什麼[會話cookie(http://www.php.net/session)。 – Mike