doudai8783 2016-09-24 18:25 采纳率: 100%
浏览 339
已采纳

单击图标时,如何从php文件调用函数?

php_file:-

class class_name{
     function method1(){
         //some code
         }
     function method2(){
         //some code
         }
}

in html:-

<i class="fa fa-angle-right" onclick=""></i>

单击图标时,如何从php文件调用函数?

  • 写回答

2条回答 默认 最新

  • doutang7661 2016-09-24 18:56
    关注

    A jquery demo is as follows:-

    abc.php:- (you can change extension to .html also if you are not going to use any php code in this file)

    <button class="fa fa-angle-right" onclick="myFunction();">Click Me Please!</button>
    
    <script src= "https://code.jquery.com/jquery-3.1.1.min.js"></script>
    
    <script type="text/javascript">
    function myFunction(){
    
         $.ajax({url: "demo_test.php", success: function(result){
            alert(result);
        }});
    }
    </script>
    

    demo_test.php:-

    <?php
    include_once('def.php');
    
    $obj = new myClass();
    
    $result = $obj->method1();
    
    echo $result;
    ?>
    

    def.php:-

    <?php
    class myClass{
        function method1(){
            echo "demo";
        }
        function method2(){
            echo "demo2";
        }
    }
    

    Output:- http://prntscr.com/clw7hu and http://prntscr.com/clw7sl

    Note:-

    All three files must be at same working location(same directory)

    It's a very small and easy sample to understand what is exactly need and how it can performed. Thanks

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算