dpy87530 2016-11-15 21:10
浏览 64
已采纳

使用jQuery发出获取php输出结果的值

I am attempting to get the value of specific looped elements. I basically have a list of records and if I click on a record, I want to be able to obtain the value of the status of that element. The status value is binary, either 0 or 1. The issues I am running into are the following:

-The click function I created is not generating a value and the alert is not showing.

-As you can see in my foreach loop, I am outputting the $status_img for $status if it meets a certain condition. The value I need is really $status.

Does anyone see what I can do to help my problems?

foreach ($rows as $row) {
            $status = $row['status'];
            $class = $status != 0 ? 'status-nonzero' : '';
            if ($status == 0) {
                $status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
            }
            else {
                $status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
            }
            $goal_date = $row['date'];
            $fixed_goal_date = fixDate($goal_date);
            $html = "";
            $html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
            $html .= '<div class="goal-box-left">';
            $html .= '<div class="goal-post-status">'.$status_img. '</div>';

jQuery:

 $('.goal-post-status').click(function (event) {
     var status = $(this).val;
     alert(status);
 });
  • 写回答

3条回答 默认 最新

  • duanmeng1950 2016-11-15 21:30
    关注

    You can set status in data-attribute then read it from jQuery:

    HTML

    $html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
    $html .= '<div class="goal-box-left">';
    $html .= '<div class="goal-post-status" data-status="'.$status.'">'.$status_img. '</div>';
    

    Javascript

    $("body").on("click", ".goal-post-status", function (event) {
        var status = $(this).attr("data-status");
        alert(status);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路