简体   繁体   English

jQuery右键单击问题

[英]JQuery Right Click Problem

I have written the following JQuery which changes dynamically generated links on my Page (ruby on rails will_paginate) to GET requests which fetches JSON and refresh elements on my page. 我编写了以下JQuery,将页面上的动态生成的链接(ruby on rails will_paginate)更改为GET请求,该请求获取JSON并刷新页面上的元素。 This works great in the case that they are left clicked. 在左键单击的情况下,这非常有用。 But in the event of a right click, the link GETS only JSON rendered information from my server and displays raw JSON in the a new window. 但是,如果单击鼠标右键,链接GETS仅会以JSON格式显示来自我的服务器的信息,并在新窗口中显示原始JSON。

How can I revert back to the original link, in the event of Right Click? 右键单击时如何恢复到原始链接?

// 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;
  });
});

Check event.which == 1 . 检查event.which == 1 This signifies left mouse button clicks. 这表示鼠标左键单击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM