我在asp.net mvc中通過ajax獲得了一個部分,它在第一次和第二次都能正常工作,但之後它重定向到通過ajax獲取頁面的頁面instad。第二次ajax調用jquery不工作
這是我的部分頁面代碼:
<script>
var jqgd = jQuery.noConflict();
jqgd(function() {
jqgd('#[email protected]').on('click', 'a', function() {
if (this.href == "") { return; }
jqgd.ajax({
url: this.href,
type: 'GET',
cache: false,
success: function (result) {
alert(result);
jqgd('#[email protected]').html(result);
}
});
return false;
});
});
</script>
<script type='text/javascript'> // Added
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 "<span class='word'>" + word + "</span>";
});
$(".word", this).filter(isEnglish).addClass('english');
$(".word", this).filter(isPersian).addClass('persian');
});
function isEnglish() {
return $(this).text().charCodeAt(0) < 255;
}
function isPersian() {
return $(this).text().charCodeAt(0) > 255;
}
});
</script>
<div id="[email protected]">
<div style="float:right;">
<div class="searchtitles" style="float: right;">@ViewBag.term</div>
<table class="jjt" cellpadding="0" cellspacing="0">
<tr class="j2t">
<td class="j13t">field</td>
<td class="j13t">field</td>
<td class="j13t">field</td>
<td class="j13t">field</td>
<td class="j13t">field</td>
<td class="j13t">field</td>
<td class="j13t">field</td>
</tr>
@foreach (var item in ViewBag.Terms)
{
Mydata
}
</table>
<div id="[email protected]" style="float:left; direction:ltr; margin-left:-20px; margin-top:-15px;">@Html.PagedListPager((IPagedList)ViewBag.Tours, page => Url.Action("results", new { page }))</div>
</div>
</div>
我使用pagedlist,當我第二次修改後的頁面,似乎所有的jQuery讚揚終止,是什麼問題? 任何人都可以幫助我嗎?
編輯:這部分代碼在第二次調用後不起作用。
<script type='text/javascript'> // Added
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 "<span class='word'>" + word + "</span>";
});
$(".word", this).filter(isEnglish).addClass('english');
$(".word", this).filter(isPersian).addClass('persian');
});
function isEnglish() {
return $(this).text().charCodeAt(0) < 255;
}
function isPersian() {
return $(this).text().charCodeAt(0) > 255;
}
});
</script>
沒有嘗試'活(「點擊」)',而不是'on' – madhushankarox
@madhushankarox:它不工作... –