dpcwz210393 2014-03-03 06:46
浏览 66
已采纳

jQuery - click事件未触发

Hello I try to make my table rows click able.

My problem is that when I click the row nothing happens.

When I place my mouse over the row the cursor does change.

My code:

<?php

session_start();

 if(isset($_SESSION[user_id]) == false || empty($_SESSION[user_id]))
  {
    header("Location: ***************");
    exit();
  }

header('Content-Type: text/html; charset=UTF-8');

if(isset($_POST[logOut]))
{
    session_destroy();

    header("Location: *************");

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>

<link rel="stylesheet" type="text/css" href="styles.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">

$(document).ready(function(){

  $('.row').click(function () {

  alert("click!");

  });

});

</script>

<script src="functions.js"></script>

<form action="" method="POST">

<input type="submit" name="logOut" value="Logout"> 

</form>

</head>

<body id="login-bg"> 

<div id="table_show">

<div class ="action_button_search" id="test">

<button type="button" onclick="getUsers()">Show users</button>

<br>

<div class="search_user">

<div class ="send_message_panel">

<textarea name="message" id="message">Enter message here...</textarea>
<br>
<button type="button" onclick="sendMessage()">Send message</button>

</div>

</div>

</div>

</div>


</body>
</html>

Table creating code:

Javascript:

function getUsers()
{
    var xmlhttp;

    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {



    parent = document.getElementById("table_show");

    var element = document.getElementById("table_container");

    var test = document.getElementById("test");

    if(element != null)
     { 
    element.parentNode.removeChild(element);
    }

    var table = document.createElement('table');
    table.innerHTML = xmlhttp.responseText;
    table.id = "table_container";
    table.className = "table_container";
    table.border = 1;

    table.appendChild(test)

    parent.insertBefore(table, parent.firstChild);

    }
  }

xmlhttp.open("POST","get_gym_users.php",true);
xmlhttp.send();

}

The PHP code:

<?php


header('Content-Type: text/html; charset=UTF-8');

$mysqli = new mysqli(*********************);

  $mysqli->set_charset("utf8");

   $sql = "SELECT id, user_name, status, last_time_seen, first_name, last_name, gender, age, gcm_id FROM user"; 

    $stmt = $mysqli->prepare($sql);

    $stmt->execute();

    $stmt->store_result();

    $stmt->bind_result($id, $user_name, $status, $last_time_seen, $first_name, $last_name, $gender, $age, $gcm_id);

    echo '<tr>
        <th>User name</th>
        <th>status</th>
        <th>Last time seen</th>
        <th>First name</th>
        <th>Last name</th>
        <th>Gender</th>
        <th>Age</th>
    </tr>';


    while ($stmt->fetch()) 
    {
        $gcmIdArray[] = $gcm_id;

        echo '<tr class="row" id="'.$id.'" ><td>'.$user_name.'</td><td>'.$status.'</td><td>'.$last_time_seen.'</td><td>'.$first_name.'</td><td>'.$last_name.'</td><td>'.$gender.'</td><td>'.$age.'</td></tr>';
    }






?>

CSS:

.row
{

cursor: pointer;

}
  • 写回答

2条回答 默认 最新

  • dso0139 2014-03-03 06:55
    关注

    Try replacing

    parent.insertBefore(table, parent.firstChild);
    

    with

    parent.insertBefore(table, parent.firstChild);
    $('.row').click(function () {
        alert("click!");
    });
    

    in JavaScript....

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

报告相同问题?

悬赏问题

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