爪哇脚本是否有可能具有带有ID的 hrefs?

是否可以添加一个包含 ID 的 href 以在运行确认函数中?我的目标是在我单击“接受”后显示一个弹出窗口,并且接受按钮从 isset 执行查询。


这是我接受的代码。


$displaybody .= "<tr>

<td>" . $rows['lname'] . ", " . $rows['fname'] . "</td>

 <td>" . $rows['subject'] . "</td>

 <td>" . $rows['days'] . " " . $rows['rstime'] . " - " . $rows['retime'] . " 

</td>

   <td>" . $rows['note'] . "</td>

  <td>

<a class='runConfirm' data-id='" . $rows['rid'] . "'>Accept</a>                

<a href='home.php?decline=" . $rows['rid'] . "'>Decline</a>

</td>

</tr>"

这是我的弹出窗口功能。(已更新)


<script type='text/javascript'> 

        $(function(){

        $('.runConfirm').click(function(event){

          // get the id you want to act on

          var theId = $(this).data('rid');


          // ask user for confirmation

          alertify.confirm('Are you sure to accept this request?',


            // accepted

            function(){


              // go to the processing page

              window.location('/accept.php?rid=' + theId);

            },


            // declined

            function(){

              alertify.error('You clicked CANCEL');

          }).set('closable', false);


        });

        });

  </script>

接受.php包含接受预订的流程。


    <?php

    include("server.php");

    session_start();


    if(isset($_GET['accept']))

    {

      $rid=$_GET['accept'];

            $query=$mysqli->query("SELECT qid FROM requests WHERE rid='".$rid."'");

                if($query->num_rows>0)

                {

                        while($rows=$query->fetch_assoc())

                        {

                            $qid=$rows['qid'];

                        }

            }


     $query1=$mysqli->query("UPDATE qualified SET status='accepted' WHERE 

   qid='".$qid."' ");

     $query=$mysqli->query("UPDATE requests SET action='accepted' WHERE 

   rid='".$rid."'");


     header("Location:home.php");

   }


   ?>


MMTTMM
浏览 120回答 1
1回答

墨色风雨

生成 DOM 时,可以将数据属性添加到“Confirm”链接,然后可以从单击回调函数访问该属性。runConfirm假设您要使用的id在中,这将给出:(为了清楚起见,仅显示更改的部分)$rows['rid']多姆生成$displaybody .= "<tr>&nbsp; <td>" . $rows['lname'] . ", " . $rows['fname'] . "</td>&nbsp; <td>" . $rows['subject'] . "</td>&nbsp; <td>" . $rows['days'] . " " . $rows['rstime'] . " - " . $rows['retime'] . "</td>&nbsp; <td>" . $rows['note'] . "</td>&nbsp; <td>&nbsp; &nbsp; <a class='runConfirm' data-id='" . $rows['rid'] . "'>Accept</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <a href='home.php?decline=" . $rows['rid'] . "'>Decline</a>&nbsp; </td></tr>"弹出窗口处理(已更新)$('.runConfirm').click(function(event){&nbsp; // get the id you want to act on&nbsp; var theId = $(this).data('id');&nbsp; // ask user for confirmation&nbsp; alertify.confirm('Are you sure to accept this request?',&nbsp; &nbsp; // accepted&nbsp; &nbsp; function(){&nbsp; &nbsp; &nbsp; // go to the processing page&nbsp; &nbsp; &nbsp; window.location = '/accept.php?rid=' + theId;&nbsp; &nbsp; },&nbsp; &nbsp; // declined&nbsp; &nbsp; function(){&nbsp; &nbsp; &nbsp; alertify.error('You clicked CANCEL');&nbsp; }).set('closable', false);});你的第三个片段将进入.accept.php您的代码将:使用行 ID 作为数据属性呈现表单击“接受”时,提示用户进行确认,并将其发送到“接受.php”页面。在服务器上运行后处理代码,最终将用户重定向到“home.php”您可以在文档中找到有关jQuery数据的更多信息:https://api.jquery.com/data/
打开App,查看更多内容
随时随地看视频慕课网APP