首页 \ 问答 \ jQuery中的mousewheel问题(Problems with mousewheel in jQuery)

jQuery中的mousewheel问题(Problems with mousewheel in jQuery)

我在头部有以下代码:

<script type='text/javascript' src='/js/jquery.mousewheel.min.js'></script>

jQuery(function($) {
    $('#box').bind('mousewheel', function(event, delta) {
        var dir = delta > 0 ? 'Up' : 'Down',
        vel = Math.abs(delta);
        alert(dir + ' at a velocity of ' + vel);
        return false;
    });
});

在Firefox 5中没有任何反应。 在Chrome 13和IE 9中,无论我在哪个方向滚动,我都会得到“NaN速度下降”。

我怎样才能解决这个问题? 我想要做的是检查用户是向上滚动还是向下滚动。

谢谢你的帮助!


I have the following code in the head-section:

<script type='text/javascript' src='/js/jquery.mousewheel.min.js'></script>

jQuery(function($) {
    $('#box').bind('mousewheel', function(event, delta) {
        var dir = delta > 0 ? 'Up' : 'Down',
        vel = Math.abs(delta);
        alert(dir + ' at a velocity of ' + vel);
        return false;
    });
});

In firefox 5 nothing happens at all. In Chrome 13 and IE 9 I get "Down at a velocity of NaN", no matter at which direction I scroll.

How can I fix this? What I want to do is to check if the user is scorlliing upwards, or if he´s scrolling downwards.

Thanks for your help!


原文:https://stackoverflow.com/questions/7022852
更新时间:2024-04-18 12:04

最满意答案

最后一个问题很容易回答:

我需要更新每一行的分数,所以我需要一个循环,但我不知道将在之前加载到数据表中的行数。 如何获取数据表中的行数

您只需使用Rows.Count属性:

Dim rowCount As Int32 = tblPatient.Rows.Count ' tblPatient => DataTable '

如果要循环所有行,可以使用foreach

For Each row As DataRow In tblPatient.Rows
    ' ... '
Next

或者for -loop:

For i As Int32 = 0 To tblPatient.Rows.Count - 1
    Dim row As DataRow = tblPatient.Rows(i)
    ' ... '
Next

要更新行,您可以使用也支持nullable-types的SetField扩展方法:

For Each row As DataRow In tblPatient.Rows
    Dim id As Int32 = row.Field(Of Int32)("ID")
    Dim race As String = row.Field(Of String)("Race")
    row.SetField("Score", CalculateScore(row))
Next

很抱歉,我无法为您提供正确的计算方法,但由于您未提供Score来源(还没有列),因此您仍然不清楚如何计算它。 但无论如何它可能会给你一个想法。


The last question is answered easily:

I need to update the score for each row so I am going to need a loop but I do not know the number of rows that will be loaded into the datatable before hand. How do I get the number of rows in the datatable?

You just have to use the Rows.Count property:

Dim rowCount As Int32 = tblPatient.Rows.Count ' tblPatient => DataTable '

If you want to loop all rows you can use a foreach:

For Each row As DataRow In tblPatient.Rows
    ' ... '
Next

or a for-loop:

For i As Int32 = 0 To tblPatient.Rows.Count - 1
    Dim row As DataRow = tblPatient.Rows(i)
    ' ... '
Next

To update the rows you can use the SetField extension method which also support nullable-types:

For Each row As DataRow In tblPatient.Rows
    Dim id As Int32 = row.Field(Of Int32)("ID")
    Dim race As String = row.Field(Of String)("Race")
    row.SetField("Score", CalculateScore(row))
Next

Sorry that i cannot provide you the correct calculation but it's still not clear how you want to calculate it since you haven't provided the source of the Score(theres no column). But it might give you an idea anyway.

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)