在第二个ajax之后调用所有jquery代码不起作用

我在asp.net mvc中通过ajax得到了一个部分,它第一次和第二次工作正常,但在那之后,所有jquery代码都停止工作。 这是我的代码:

 var jqgd = jQuery.noConflict(); jqgd(function () { jqgd('#getdata-@ViewBag.term').on('click', '#getdata-@ViewBag.term a', function () { if (this.href == "") { return; } jqgd.ajax({ url: this.href, type: 'GET', cache: false, success: function (result) { alert(result); jqgd('#retrieve-@ViewBag.term').html(result); } }); return false; }); });   //This function jQuery(function ($) { $("div, p, a, b, strong, bold, font, span, td") .filter(function () { return $(this).children(":not(.word)").length == 0 }) .each(function () { this.innerHTML = $(this).text().replace(/\S+/g, function (word) { return "" + word + ""; }); $(".word", this).filter(isEnglish).addClass('english'); $(".word", this).filter(isPersian).addClass('persian'); }); function isEnglish() { return $(this).text().charCodeAt(0)  255; } });  
@ViewBag.term
@foreach (var item in ViewBag.Terms) { Mydata }
field field field field field field field
@Html.PagedListPager((IPagedList)ViewBag.Tours, page => Url.Action("results", new { page }))

我在代码中注释为“ 此函数 ”的部分代码不起作用。 我也在布局中使用了弹出式弹出窗口,在第二次调用后它无效。 似乎我的所有jquery代码在第二次调用后都停止工作。

什么问题?

尝试这样的事情

    

只需创建要执行的代码function即可。

因为你的代码运行在初始元素上,它存在于DOM上的DOM中。

在ajax之后,你得到了一个代码没有运行的新元素,所以把你的代码放在函数中并在你的ajax调用之后调用它。