第二次调用 AJAX 后失去 TR 点击操作


losing TR onclick action after calling AJAX the second time

我想做的是调用创建表的PHP文件,但我对JQuery不太熟悉。 请帮忙。 第二次调用 AJAX 后,我失去了 TR 中的点击和突出显示。

$.ajax({
    url: 'save-all.php',
    async: false,
    data: $(this).serialize(),
    type: 'POST',
    success: function (msg) {
        if (msg == 'true') {
            $.get('orgs-list.php', {}, function (data) {
                $('#tbl-content1').replaceWith($(data));
                $("#success").show().fadeOut(3000);
            });
        } else {
            $("#error").show().fadeOut(3000);
        } //end #msg==true
    } //end #success
}); //end #ajax

和 PHP 文件:

$stid = oci_parse($connection, 'SELECT org_id, agency, pobox, address1, address2, city, state, zipcode, realty_organizations.org_type AS org_type, realty_orgtype.org_type AS agencytype
FROM wflhd_admin.realty_organizations, wflhd_admin.realty_orgtype 
    WHERE realty_organizations.org_type = realty_orgtype.typeid
        ORDER BY agency'); 
oci_execute($stid);
$nrows = oci_fetch_all($stid, $res, null, null, OCI_FETCHSTATEMENT_BY_ROW);   
?>
<table id='tbl-content1' cellpadding='3' width='100%' cellspacing='0' border='1' style='font-family:verdana; font-size: 11px;' >
<?              
for ($i=0; $i<=$nrows; $i++) {?>    
<tr id="row_<? echo $res[$i]['ORG_ID']; ?>" onClick="DoNavOrg('<? echo $res[$i]['ORG_ID']; ?>','<? echo $res[$i]['AGENCY'] ?>','<? echo $res[$i]['POBOX'] ?>','<? echo $res[$i]['ADDRESS1']; ?>','<? echo $res[$i]['ADDRESS2']; ?>','<? echo $res[$i]['CITY']; ?>','<? echo $res[$i]['STATE']; ?>','<? echo $res[$i]['ZIPCODE']; ?>','<? echo $res[$i]['ORG_TYPE']; ?>'); return false;">   
}
对我来说,

这听起来像是你第一次拥有它,因为在DocumentReady上,第一个TR被绑定为DOM元素,这就是jQuery选择它的原因。

动态添加 HTML/DOM 元素后,您应该使用 .bind() 将它们绑定到所需的功能中http://api.jquery.com/bind/

所以试着做这样的事情,

    $( ".your-newly-added-tr" ).bind( "click", function() {
        // call what ever you need, "DoNavOrg" or anything else... 
    });

希望对您有所帮助。 :)