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

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

從 <button onclick=""> 執行 PHP 函數

從 <button onclick=""> 執行 PHP 函數

米脂 2023-12-25 16:53:41
我想在單擊 HTML 按鈕時執行 PHP 腳本。我知道,我不能這樣做: <button onclick="myPhpFunction("testString")">Button</button> 或類似的事情。我的目標是,單擊此按鈕時在我的服務器上執行一些命令。注意:我的 php 函數需要來自 JS/HTML 的變量。有沒有辦法做到這一點?
查看完整描述

1 回答

?
慕少森

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

如何通過單擊按鈕調用 PHP 函數?

<h1 style="color:green;">?

? ? GeeksforGeeks?

</h1>?


<h4>?

? ? How to call PHP function?

? ? on the click of a Button ??

</h4>?


<?php

? ? if(array_key_exists('button1', $_POST)) {?

? ? ? ? button1();?

? ? }?

? ? else if(array_key_exists('button2', $_POST)) {?

? ? ? ? button2();?

? ? }?

? ? function button1() {?

? ? ? ? echo "This is Button1 that is selected";?

? ? }?

? ? function button2() {?

? ? ? ? echo "This is Button2 that is selected";?

? ? }?

?>?


<form method="post">?

? ? <input type="submit" name="button1"

? ? ? ? ? ? class="button" value="Button1" />?


? ? <input type="submit" name="button2"

? ? ? ? ? ? class="button" value="Button2" />?

</form>?

查看完整回答
反對 回復 2023-12-25
  • 1 回答
  • 0 關注
  • 196 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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