【问题标题】:Function is not getting called on clicking the button单击按钮时未调用函数
【发布时间】:2021-11-19 09:34:14
【问题描述】:

这段代码在first.php中


function fas(){
    echo "fuction";
    echo "Anything";
}

if(isset($_POST['btn'])){
    fas();
}
?>

second.php 中的代码

<?php 
include 'first.php'
?>

<!DOCTYPE html>
<head>
    <title>Document</title>
</head>
<body>
    <button type= "submit" name = "btn"> click this</button>
</body>
</html>

单击按钮时,不会调用函数 fas。有什么问题?

【问题讨论】:

  • 您有一个提交按钮,但没有任何 to 实际提交...这需要在按钮周围有一个form

标签: php html frontend


【解决方案1】:

您可以将按钮放在form 标记中,然后是这样的按钮:

<form action="/" method="post">
  <button type="submit">Submit</button>
</form>

或者你可以这样做:

<button onclick="function_name()">Submit</button>

第二个是直接调用函数,而不是像表单那样转到单独的链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    • 1970-01-01
    相关资源
    最近更新 更多