javascript - 回发后不显示我在 JavaScript 中右键单击显示的列表

标签 javascript jquery asp.net

当用户右键单击 GridView 的行并且 GridView 在 UpdatePanel 中时,我使用下面的 JavaScript 代码显示列表。发生回发时,它不会显示列表。

$(document).ready(function () {
    //--------------- Info Box --------------------
    $('.CityItem').mouseup(function (e) {
       if ( e.which === 3 ) {
          $('.CityItem').children('.CompanyList').hide();
          $(this).children('.CompanyList').toggle();

          $(this).children('.CompanyList').css('top', e.pageY - 300 );
          $(this).children('.CompanyList').css('left', e.pageX - 175 );
       }
       e.preventDefault();
    });
    $('.CityItem').hover( function () {
       $(this).children('.CompanyList').hide();
    });
});

最佳答案

// Attach a handler to the load event.
Sys.Application.add_load(applicationLoadHandler);

将处理程序(上面的代码)放在 updatePanel 中。然后 applicationLoadHandler 将在更新面板刷新时执行。

function applicationLoadHandler() {
   //--------------- Info Box --------------------
    $(document).on('mouseup', '.CityItem', function (e) {
       if ( e.which === 3 ) {
          $('.CityItem').children('.CompanyList').hide();
          $(this).children('.CompanyList').toggle();

          $(this).children('.CompanyList').css('top', e.pageY - 300 );
          $(this).children('.CompanyList').css('left', e.pageX - 175 );
       }
       e.preventDefault();
    });
    $(document).on('hover', '.CityItem',function () {
       $(this).children('.CompanyList').hide();
    });
    }

关于javascript - 回发后不显示我在 JavaScript 中右键单击显示的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19354260/

相关文章:

ASP.NET MVC + jQuery + IIS6 : Multiple Ajax requests

javascript - 获取地址栏中特定字符后的值

javascript - 我该如何解决这个 Javascript/CSS 问题?

javascript - 为什么 .alert() 永远只显示相同的值?

jquery - Bootstrap 导航 - 从底部到顶部/词缀

asp.net - checkbox 和它的 label 在同一层级

c# - 在数据绑定(bind)表达式中调用具有 void 返回类型的方法

javascript - 仅变换 Path2D 的样式

javascript - 如何对 Bootstrap 卡进行分页

javascript - 如何检测是否加载了 iframe?