dongshi1934 2016-02-07 21:45
浏览 15

在javascript按钮中添加功能[重复]

This question already has an answer here:

I want my btn-post-announcement to have a function that is when I click the Post button the data's in the table will be inserted in the database.

<div id='donor_table'>

    <div style='height: 600px; width: 100%; overflow: scroll'>

        <table id='donor_tbl' border='5' cellpadding='10'>
            <thead>
            <th>#</th>
            <th>Announcements</th>
            <th>Date</th>
            <th>Time</th>
            <th>Post</th>
            </thead>
            <tbody>

            <?php
            include "connection.php";
            error_reporting(0);
            $searchannouncement = $_POST['searchannouncement'];
            $displayAnn = " SELECT annid,announcement,dateee,timeee FROM announcements_tbl WHERE annid LIKE '%" . $searchdonor . "%' OR announcement LIKE '%" . $searchdonor . "%' OR dateee LIKE '%" . $searchdonor . "%' OR timeee LIKE '%" . $searchdonor . "%' order by annid desc";

            $annData = mysql_query($displayAnn);
            while ($drecords = mysql_fetch_assoc($annData)) {
                echo "<tr><td>" . $drecords['annid'] . "</td>";
                echo "<td>" . $drecords['announcement'] . "</td>";
                echo "<td>" . $drecords['dateee'] . "</td>";
                echo "<td>" . $drecords['timeee'] . "</td>";
                echo "<td align='center'><input type='button' class='btn-post-announcement button' id=" . $drecords['annid'] . " value='Post'></td>";
            };
            ?>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>
<div id="dlg">
    <div>
        <script type="text/javascript">
            $(function () {
                $("#dlg").dialog({
                    autoOpen: false,
                    height: 600,
                    width: 780,
                    modal: true
                });
                $(".btn-post-announcement").button();
                $(".btn-post-announcement").click(function () {
                })
                $("#donor_tbl").DataTable();
            });
        </script>
</div>
  • 写回答

1条回答 默认 最新

  • dousi5501 2016-02-07 21:59
    关注

    You will need ajax to achieve this. I will use Jquery to do so:

    JS

    $(function(){
      $('.btn-post-announcement').click(function(){ // on button pressed
        var data = {};
        var count = 0;
       $('td').each(function(){        // for each td 
         data[count++] = $(this).text(); // collect the text inside it
       })
        $.post("url.php", data, function(resp){ // send the collected data to the PHP 
           console.log(response)
        })
      })
    })
    

    url.php

    <?php
     var_dump($_POST);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度