php - AJAX 之后 Jquery 不工作

标签 php javascript jquery ajax

使用此代码:

    $("table > :not(thead) > tr.Selected").removeClass('Selected')

查找具有 Selected 类的所有表行并删除该类。

另外,使用此代码:

    var ReqID = $("table > :not(thead) > tr.Selected").attr('id')

它试图从选择了类的行中查找 ID。

这段代码可以完美地工作,直到使用 AJAX 重新加载表,然后一切都停止工作并且该行不起作用。

有什么想法吗?

谢谢!

编辑

更多代码:

这是 AJAX 调用:

function EditRequest()
{var ReqID = $("table > :not(thead) > tr.Selected").attr('id')
alert(ReqID);
$.post("a/outputresults2.php", {editdynamic: ReqID} ,      function(data){
$('#resultstable').html(data);
});

}

function Selected(x)
{
$("table > :not(thead) > tr.Selected").removeClass('Selected')
$('#'+x).toggleClass('Selected');
}

这是输出原始数据和 AJAX 更新后的表格的 php:

    if($RequestID == $ID){
                $requestrows.="
    <tr id=\"$RequestID\" onClick=\"Selected($RequestID)\" class=\"Selected\" >
        <td><input type=\"text\"  id=\"MCode\" value=\"$ModCode\"></td>
        <td><input type=\"text\"  id=\"RName\" value=\"$RoomName\"></td>
  ..etc etc etc

    </tr>"; 
    }
    }
    if($RequestID != $ID){
$requestrows .=
"       <tr id= \"$RequestID\" onClick=\"Selected($RequestID)\" > 
        <td>$ModCode</td>
        <td>$RoomName</td>
        ... etc etc etc

    </tr>"; 
    }
}



echo($requestrows);

动态更改的表称为结果表

谢谢

最佳答案

您可能需要使用实时单击事件来调用事件,以正确绑定(bind)新加载的对象:

$('#my_trigger').live('click', function() {
  .. some code
})

将有助于从您那里获得有关您使用此功能的确切方式的更多信息。

看看 jquery live docs

关于php - AJAX 之后 Jquery 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9286629/

相关文章:

javascript - 图片宽度 :auto and max-height after changing parent block height

php - mysql查询没有从表中获取所有元素

PHP 和 MySQL InnoDB : Data not available immediately after insert or update

javascript - Ajax,JS函数返回未定义的值

javascript - 如何在javascript中切换图像位置?

javascript - 使用parentsUntil或不使用parentUntil在 TreeView 中触发单击事件来搜索节点

php - 如何将两个数组值连接到另一个数组中

javascript - 滚动到特定点时删除 iframe

jquery - 单击元素外部任意位置时隐藏元素

jquery - JqG​​rid 未填充数据