首页 \ 问答 \ Chrome 11+(可能还有IE)在设置值后不会触发OnChange(Chrome 11+ (and possibly IE) not triggering OnChange after value set)

Chrome 11+(可能还有IE)在设置值后不会触发OnChange(Chrome 11+ (and possibly IE) not triggering OnChange after value set)

前段时间我为jQuery编写了一个输入掩码扩展,它自动过滤掉输入元素中的任何非十进制/整数值,我今天才发现,如果keyup事件改变了输入的值,则不再调用onchange事件:

示例: http//jsfiddle.net/At8Ht/37/

如果你在Firefox中查看它,它将显示“Halp!” 更改后输入下方,当输入模糊/失去焦点时,但在Chrome中则没有。

有没有人有什么建议? 实际上,我想要做的就是在用户输入大数字时自动插入逗号,例如在用户放开“2”键后输入“1552”会产生“1,552”。 这工作正常,直到Chrome 11/12 :(


A while back I wrote an input mask extension for jQuery which automatically filters out any non-decimal/integer values from a input elemnt, I just discovered today that this is no longer calling the onchange events if the keyup event changes the value of the input:

Example: http://jsfiddle.net/At8Ht/37/

If you view this in Firefox, it will display "Halp!" beneath the input after it is changed,when the input is blurred/loses focus, but in Chrome it does not.

Does anyone have any suggestions? Really all I am trying to do is automatically insert commas while the user is typing a large number, for example typing in "1552" yields "1,552" after the user lets go of the "2" key. This was working fine up until Chrome 11/12 :(


原文:https://stackoverflow.com/questions/6364823
更新时间:2024-03-26 18:03

最满意答案

分析聚合中的代码片段的运行时可能是最容易的。 在外循环的第一次迭代中,内循环将运行1次。 在外循环的第二次迭代中,内循环将运行2次。 在外循环的第三次迭代中,内循环将运行4次。 更一般地说,在外循环的第k次迭代中,内循环将运行2k次。 一旦i变得大于N,外循环就会停止,这发生在log 2 N次迭代之后。

如果我们总结完成的工作总量,我们会看到它

1 + 2 + 4 + 8 + ... + 2 log 2 N = 2 log 2 N + 1 - 1 = 2n - 1

(这使用1 + 2 + 4 + 8 + ... + 2 k = 2 k + 1 - 1的事实)。 因此,对整个代码(即包括两个循环)所做的总工作是O(n)。


It might be easiest to analyze the runtime of the piece of code in the aggregate. On the first iteration of the outer loop, the inner loop will run 1 time. On the second iteration of the outer loop, the inner loop will run 2 times. On the third iteration of the outer loop, the inner loop will run 4 times. More generally, on the kth iteration of the outer loop, the inner loop will run 2k times. The outer loop stops as soon as i becomes greater than N, which happens after log2 N iterations.

If we sum up the total work done, we'll see that it's

1 + 2 + 4 + 8 + ... + 2log2 N = 2log2 N + 1 - 1 = 2n - 1

(This uses the fact that 1 + 2 + 4 + 8 + ... + 2k = 2k+1 - 1). Therefore, the total work done for the entire piece of code (that is, including both loops) is O(n).

相关问答

更多
  • 分析聚合中的代码片段的运行时可能是最容易的。 在外循环的第一次迭代中,内循环将运行1次。 在外循环的第二次迭代中,内循环将运行2次。 在外循环的第三次迭代中,内循环将运行4次。 更一般地说,在外循环的第k次迭代中,内循环将运行2k次。 一旦i变得大于N,外循环就会停止,这发生在log 2 N次迭代之后。 如果我们总结完成的工作总量,我们会看到它 1 + 2 + 4 + 8 + ... + 2 log 2 N = 2 log 2 N + 1 - 1 = 2n - 1 (这使用1 + 2 + 4 + 8 + . ...
  • “经验”(根据输入大小计算运行时间)的问题只适用于提供的测试用例 。 “理论”分析为您提供了算法的所有缺陷,您可以使用数学分析真正的最佳案例/平均案例/ ......并保证是正确的。 一个很好的常见例子是单纯形算法 ,它通常非常快速,但对于某些输入偶尔会有指数最差情况下的运行时间。 另一方面,由于渐近分析忽略了常量,并且仅适用于“足够大的输入”,所以如果预期输入相对较小,则它们几乎没有用处,并且难以区分具有相同复杂度的两种算法类,但具有不同的常量,常量在生产代码中很重要。 tl; dr :每个人都有自己的用 ...
  • 对于大n,k几乎总是大于log(n)。 例如,对于n = 1024,log(1024)= 10您将执行循环的概率是P = log(n)/ n所以时间将是 (log(n)/n)*(n*log(n))+ O(RandomFunc(n)) 所以一切都依赖于O(Random(n))。 如果O(Random(n))= O(n) O(n)>O(log(n)^2) = O(n) 第4-10行是O(nlog(n)) For big n, k almost always bigger then log(n). For e ...
  • 继评论之后: 首先解决(2),因为它更直接。 您的扩展尝试是正确的。 写作略有不同: A ,谐波序列 - 渐近等于自然对数: γ = 0.57721...是Euler-Mascheroni常数 。 B ,逆平方和 - 无限和是着名的巴塞尔问题 : 这是1.6449... 因此,因为B单调递增,所以它总是O(1) 。 (2)的总复杂度简单地为Θ(log n) 。 (1)有点乏味。 小O符号: 严格降低复杂等级,即: 假设一组N函数{F_i}按照复杂度递减的顺序排列,即F2 = o(F1)等等。对它们进行线性组 ...
  • 这个函数的大O是O(n),因为你只遍历队列两次。 理论上这也是如此,如果你做K次,其中K是一个常数,并且它不随队列大小n而改变。 例如,O(n ^ 2)是你在另一个循环内部有一个循环,所以你正在遍历n * n次的队列。 您也可以检查: 哪种算法更快O(N)或O(2N)? The Big O for this function is O(n) because your traversing the queue only twice. Theoretically this is also true if you ...
  • f∈O(g)基本上说 对于常数k> 0的至少一个选择,可以找到一个常数a,使得对于所有x> a,不等式0 <= f(x)<= kg(x)。 请注意,O(g)是此条件成立的所有函数的集合。 f∈o(g)基本上说 对于常数k> 0的每一个选择,你可以找到一个常数a,使得对于所有x> a,不等式0 <= f(x)
  • 当i=1 ,k-loop运行1次,j-loop运行1次。 总计= 1.1 = 1次 当i=2 ,k-loop运行2次,j-loop运行2次。 总计= 2.2 = 4次 当i=3 ,k-loop运行3次,j-loop运行3次。 总计= 3.3 = 9次 当i=n ,k-loop运行n次,j-loop运行n次。 总= nn = n ^ 2次 因此,算法的时间复杂度为O(1 + 2 ^ 2 + 3 ^ 2 + ... n ^ 2)= O(n(n + 1)(2n + 1)/ 6)= O(n ^ 3) When i= ...
  • 方法是通过解决复发 F(j+1) = f(F(j)), F(0) = a. 然后解决不公平问题 F(k(n)) < n <= F(k(n)+1), 对于k(n) ,复杂度为O(k(n)) 。 例如, f(j):= j²产生 F(j+1) = F²(j), F(0)= a 哪个有解决方案 F(j) = a^(2^j). 然后通过倒置 k(n) ~ log(log(n)/log(a))/log(2) = O(log(log(n))). The approach is by solving the r ...
  • 准备工作 上面图像中红色标记部分上方的部分是Big-Θ符号的定义:“ f(n) Θ(g(n)) ”, f(n) = (n + a)^b, b > 0 (+) g(n) = n^b (++) 我们将重复这个不等式,以便在显示它如下所示时简化参考: f(n) is in Θ(g(n)) with f(n) and g(n) as in (+) and (++), respectively <=> c_1⋅n^b ≤ (n + a)^b ≤ c_2⋅ ...
  • 鉴于, f(x) = xlogx+3logx^2 = xlogx+6logx // since log (a^b) = b log a 众所周知, f(x)= O(g(x)),如果| f(x)| <= M. | g(x)|,其中M是正实数 。 因此,对于M> = 7且x在实际正范围内变化, M . x log x >= x log x + 6 log x >= (x+6) log x. f(x) = x log x + 3log x^2 = ...

相关文章

更多

最新问答

更多
  • Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)
  • C ++ 11 + SDL2 + Windows:多线程程序在任何输入事件后挂起(C++11 + SDL2 + Windows: Multithreaded program hangs after any input event)
  • AccessViolationException未处理[VB.Net] [Emgucv](AccessViolationException was unhandled [VB.Net] [Emgucv])
  • 计算时间和日期差异(Calculating Time and Date difference)
  • 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
  • C#对象和代码示例(C# objects and code examples)
  • 在python中是否有数学nCr函数?(Is there a math nCr function in python? [duplicate])
  • 检索R中列的最大值和第二个最大值的行名(Retrieve row names of maximum and second maximum values of a column in R)
  • 给定md5哈希时如何查找特定文件(How to find specific file when given md5 Hash)
  • Python字典因某些原因引发KeyError(Python Dictionary Throwing KeyError for Some Reason)
  • 如何让Joomla停止打开新标签中的每个链接?(How do I get Joomla to stop opening every link in a new tab?)
  • DNS服务器上的NS记录不匹配(Mismatched NS records at DNS server)
  • Python屏幕捕获错误(Python screen capture error)
  • 如何在帧集上放置div叠加?(How to put a div overlay over framesets?)
  • 页面刷新后是否可以保留表单(html)内容数据?(Is it possible to retain the form(html) content data after page refreshed?)
  • 使用iTeardownMyAppFrame和iStartMyAppInAFrame在OPA5测试中重新启动应用程序超时(Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out)
  • 自动拆分文本内容到列(Automatically splitting text content into even columns)
  • 在r中的循环中将模型名称分配给gbm.step(assigning model names to gbm.step in loop in r)
  • 昆明哪里有电脑等级考试二级C培训?
  • C ++模板实例化,究竟是什么意思?(C++ template instantiation, what exactly does it mean?)
  • 帮助渲染来自fields_for的部分内容(Help to render a partial from fields_for)
  • 将url.action作为json对象返回mvc(return url.action as json object mvc)
  • 使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
  • 将bindingRedirect添加到.Net标准库(Adding a bindingRedirect to a .Net Standard library)
  • Laravel版本升级会影响您的控制器吗?(Laravel version upgrade affects your controller?)
  • imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
  • 如何在eclipse debug impala前端
  • 如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])
  • 使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)
  • JS 实现一个菜单效果