为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
MMTTMM 2022-09-25 20:38:01
是否可以添加一个包含 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");   }   ?>
查看完整描述

1 回答

?
墨色风雨

TA贡献1853条经验 获得超6个赞

生成 DOM 时,可以将数据属性添加到“Confirm”链接,然后可以从单击回调函数访问该属性。runConfirm


假设您要使用的id在中,这将给出:(为了清楚起见,仅显示更改的部分)$rows['rid']


多姆生成


$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>"

弹出窗口处理(已更新)


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

  // get the id you want to act on

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


  // 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);


});

你的第三个片段将进入.accept.php

您的代码将:

  1. 使用行 ID 作为数据属性呈现表

  2. 单击“接受”时,提示用户进行确认,并将其发送到“接受.php”页面。

  3. 在服务器上运行后处理代码,最终将用户重定向到“home.php”

您可以在文档中找到有关jQuery数据的更多信息:https://api.jquery.com/data/


查看完整回答
反对 回复 2022-09-25
  • 1 回答
  • 0 关注
  • 71 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号