Jquery 表中任何链接的选择器是什么

Jquery 表中任何链接的选择器是什么,jquery,selector,Jquery,Selector,我有一个带有下拉选择器的php页面,当选择器被更改时,我使用jquery、ajax和mysql生成一个表,并将其放入名为.mytable的div中。表中的一些数据是指向影响表中数据的php脚本的链接,因此我希望在不重新加载的情况下刷新表 我知道我需要通过将事件侦听器附加到表中的链接来实现这一点,但我似乎无法获得将侦听器附加到的正确选择器 任何帮助都将不胜感激 用户看到的名为user.php的页面是: <!DOCTYPE HTML> <html> <head>

我有一个带有下拉选择器的php页面,当选择器被更改时,我使用jquery、ajax和mysql生成一个表,并将其放入名为.mytable的div中。表中的一些数据是指向影响表中数据的php脚本的链接,因此我希望在不重新加载的情况下刷新表

我知道我需要通过将事件侦听器附加到表中的链接来实现这一点,但我似乎无法获得将侦听器附加到的正确选择器

任何帮助都将不胜感激

用户看到的名为user.php的页面是:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="css/table_style.css" rel="stylesheet" type="text/css">
</head>



<body>
<form name="form1" method="post" action="">
  <label for="select_data"></label>
  <select name="select_data" id="select_data">
    <option value=1>"Apples"</option>
    <option value=2>"Pears"</option>
    <option value=3>"Bananas"</option>
  </select>
</form>

<div id="mytable">This is where the table goes</div>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="get_table.js"></script>
</body>
</html>
事件处理程序调用的创建表并返回html代码的脚本为:

<?php

require_once('Connections/dbc.php');
$fruit=$_POST['fruit'];
$sql="SELECT * FROM q_fruit WHERE FruitID =".$fruit;
$rec1=mysqli_query($dbc,$sql);

    echo '<table class="table" align="center">';
    echo '<th class="th" width="80px">Fruit ID</th>';
    echo '<th class="th" width="150px">Fruit Name</th>';
    echo '<th class="th" width="40px">Fruit Action 1</th>';
    echo '<th class="th" width="150px">Fruit Action 2</th>';

    while ($row=mysqli_fetch_array($rec1)) 
        {

            echo '<tr class="tr">';
            echo '<td class="td">'.$row['FruitID']. '</td>';    
            echo '<td class="td">'.$row['FruitName']. '</td>'; 
            echo '<td class="td"><a class="fruit_link" href="fruitaction1.php">'.$row['FruitID']. '</a></td>'; 
            echo '<td class="td"><a class="fruit_link" href="fruitaction2.php">'.$row['FruitID']. '</a></td>'; 
            echo '</tr>';
         }

    echo '</table>';


    mysqli_free_result($rec1);
    mysqli_close($dbc);

?>

因此,select事件处理程序在每次更改值时都会重新生成表,但链接处理程序不是这样,我认为是这样的,因为链接在返回的html中,而不是java正在侦听的用户文件中。有办法解决这个问题吗?

我不确定,这是否像$table a那么简单,但看起来是这样的。。。这将选择所有表中的所有锚点


如果只想在该表中选择它们,那么$div.mytable table a(如果调用)表示类,但如果它是一个ID并且确实以点开头,那么$div.mytable table a.

$'.mytable tr td a'。单击函数{}应该在这里发布你的代码。这可以通过使用AJAX轻松做到,并检查这一点。我理解这背后的原理,但我遇到的问题是,完整的html表在php脚本中被回显到一个div。因此,侦听器不会捕获表中的链接。但是脚本中已经存在的链接正在被捕获。目标是在组合框的值被更改时,使用jquery创建一个表,将组合框中的值作为sql查询的一部分。生成的表将在数据单元格中有链接,单击这些链接时应执行后台php脚本或函数,以更改数据库并刷新表,而无需离开页面。您可以在$'divmytable'.htmldata;之后分配侦听器;,这将把它们附加到新的元素上,感谢回复balint,但我不确定你的确切意思,你能更具体一点吗?这是一个答案,因此表中的链接不会被侦听器捕获。如果在将表添加到页面后分配jquery侦听器,并选择新表,那么它将工作。
<?php

require_once('Connections/dbc.php');
$fruit=$_POST['fruit'];
$sql="SELECT * FROM q_fruit WHERE FruitID =".$fruit;
$rec1=mysqli_query($dbc,$sql);

    echo '<table class="table" align="center">';
    echo '<th class="th" width="80px">Fruit ID</th>';
    echo '<th class="th" width="150px">Fruit Name</th>';
    echo '<th class="th" width="40px">Fruit Action 1</th>';
    echo '<th class="th" width="150px">Fruit Action 2</th>';

    while ($row=mysqli_fetch_array($rec1)) 
        {

            echo '<tr class="tr">';
            echo '<td class="td">'.$row['FruitID']. '</td>';    
            echo '<td class="td">'.$row['FruitName']. '</td>'; 
            echo '<td class="td"><a class="fruit_link" href="fruitaction1.php">'.$row['FruitID']. '</a></td>'; 
            echo '<td class="td"><a class="fruit_link" href="fruitaction2.php">'.$row['FruitID']. '</a></td>'; 
            echo '</tr>';
         }

    echo '</table>';


    mysqli_free_result($rec1);
    mysqli_close($dbc);

?>