我已经编写了下面的JQuery,它在我的页面上更改动态生成的链接(ruby on rails will_paginate),以GET请求获取页面上的JSON和刷新元素。这在左键点击的情况下效果很好。但是在右键单击的情况下,只有GETS链接从我的服务器呈现信息,并在新窗口中显示原始JSON。JQuery右键单击问题
如何在右键点击的情况下恢复原始链接?
// will_paginate + ajax
// updates two divs: #pages and #pagelink
// see places#search controller; passes 4 parameters to the search action
$(function(){
$(".pagination a").live("click", function(event) {
event.preventDefault();
// Javascript Regular expression function; extracts page number from full url
var extractPageNumber = function(s) {
var r=/page=(\d+)/, m=(""+s).match(r);
return (m) ? Number(m[1]) : undefined;
};
var pageregex = extractPageNumber($(this).attr('href'));
$(".pagination").html("Page is loading...")
$.get("/event", { event: $("input[name=event]").val(), page: pageregex }, function(data) {
$('#pagelink').html(data.page_link);
$('#tweets').html(data.html);
});
return false;
});
});
我看到邪恶的“活”功能。切换到'delegate':'$(“。pagination”)。委托('a','click',function(event){event} event.preventDefault();。。。'' –