【问题标题】:jQuery select by class and pass current element as parameter in ASP.NETjQuery 按类选择并将当前元素作为 ASP.NET 中的参数传递
【发布时间】:2011-02-17 18:38:24
【问题描述】:

这是我的代码:

$(document).ready(function(){  
    $('.classOne').mouseover(function(e) {  
        alert($(e).attr('id'));  
    });  
});  

现在,我知道我的代码实际上有问题,为了获得带有当前 asp:LinkButton 的 ID 的结果,我将其悬停在 alert() 消息中,什么是正确的?
感谢所有帮助者!

【问题讨论】:

    标签: asp.net jquery mouseover parameter-passing


    【解决方案1】:

    你应该这样做:

    $(document).ready(function(){
       $('.classOne').mouseover(function() {
          alert($(this).attr('id'));
       });
    });
    

    【讨论】:

      【解决方案2】:

      e 是您的事件,而不是您的元素。您的元素包含在此函数中。

      
      $(document).ready(function() {
          $('.classOne').mouseover(function(e) {
              alert($(this).attr('id'));
          });
      });
      

      【讨论】:

        【解决方案3】:

        几个假设:

        • 链接按钮使用有效类“classOne”呈现
        • 按钮未通过 AJAX 回调添加到页面集合中
        • 'e' 参数实际上是事件的对象而不是 HTML 元素的对象

          (文档).ready(函数(){
          $('.classOne').bind('mouseover', function(){
          警报($(this).attr('id'));
          });
          });

        【讨论】:

          猜你喜欢
          • 2012-12-17
          • 1970-01-01
          • 2011-06-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-11-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多