亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

按下按鈕時加一(在 Ajax 調用中)

按下按鈕時加一(在 Ajax 調用中)

PHP
qq_遁去的一_1 2022-10-14 14:25:19
我有一些標記<span class="points-count">0</span>。按下按鈕時,我想在 php.ini 中將此值增加一。我如何實現這一目標?
查看完整描述

3 回答

?
PIPIONE

TA貢獻1829條經驗 獲得超9個贊

如果您真的想使用 ajax 調用來計算數字,這里是示例:


計數器.php:


<?php

    $counter = $_GET['current_value'] + 1;       //value is increase here

    echo json_encode(['new_value' => $counter]); //return the value in JSON format

?>

您的 HTML 文件:


<span class="points-count">0</span>

<button onclick="count()">Increase</button>


<script type="text/javascript">

    function count() {

        $.ajax({

            url     : "counter.php",

            type    : "GET",

            dataType: "json",

            data    : {

                current_value: $(".points-count").html() //set value here

            },

            success: function(data) {

                $(".points-count").html(data.new_value); //finally, get the returned value of the php script

            }

        });

    }

</script>


查看完整回答
反對 回復 2022-10-14
?
弒天下

TA貢獻1818條經驗 獲得超8個贊

您可以使用jQuery、javascript等來完成此操作,如果您只想使用PHP,請檢查此代碼


    <?php  


$current_value = 0;

if($_POST['count']){

    $current_value = $_POST['count'];

    $current_value++;} 

?>

<form action="" method="POST">

    <span class="points-count"><?=$current_value?></span>

    <input type="hidden" name="count" value="<?=$current_value?>">

    <button type="submit">Add</button>

</form>


查看完整回答
反對 回復 2022-10-14
?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

而不是使用 php。您可以為此使用 jquery 或 javascript。php 僅用于服務器端渲染。



查看完整回答
反對 回復 2022-10-14
  • 3 回答
  • 0 關注
  • 131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號