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).

相关问答

更多

嵌套循环渐近分析(Nested Loops Asymptotic analysis)

分析聚合中的代码片段的运行时可能是最容易的。 在外循环的第一次迭代中,内循环将运行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 + ...

图的差分和渐近分析比较算法的运行时间(Difference between graphs and asymptotic analysis to compare running times of an algorithm)

“经验”(根据输入大小计算运行时间)的问题只适用于提供的测试用例 。 “理论”分析为您提供了算法的所有缺陷,您可以使用数学分析真正的最佳案例/平均案例/ ......并保证是正确的。 一个很好的常见例子是单纯形算法 ,它通常非常快速,但对于某些输入偶尔会有指数最差情况下的运行时间。 另一方面,由于渐近分析忽略了常量,并且仅适用于“足够大的输入”,所以如果预期输入相对较小,则它们几乎没有用处,并且难以区分具有相同复杂度的两种算法类,但具有不同的常量,常量在生产代码中很重要。 tl; dr :每个人都...

渐近预期运行时间(Asymptotic Expected Running Time)

对于大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). ...

难以渐近(递归)函数(算法分析)(difficult asymptotic(recurrence) function (algorithm analysis))

继评论之后: 首先解决(2),因为它更直接。 您的扩展尝试是正确的。 写作略有不同: A ,谐波序列 - 渐近等于自然对数: γ = 0.57721...是Euler-Mascheroni常数 。 B ,逆平方和 - 无限和是着名的巴塞尔问题 : 这是1.6449... 因此,因为B单调递增,所以它总是O(1) 。 (2)的总复杂度简单地为Θ(log n) 。 (1)有点乏味。 小O符号: 严格降低复杂等级,即: 假设一组N函数{F_i}按照复杂度递减的顺序排列,即F2 = o(F1)等等。对它们...

倒排队列的渐近分析(Asymptotic Analysis of Reversing a Queue)

这个函数的大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 i...

渐近分析“o”到“O”的转换(Asymptotic analysis “o” to “O” conversion)

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)<kg(x)。 再次注意,o(g)是一个集合。 维基百科: 注意大O符号的早期形式定义与小O的当前定义之间的区别:前者对于至少一个常数M必须是正确的,后者必须对每个正常数ε保持不变,但是很小。 ...

嵌套循环时间分析(Nested Loops Time Analysis)

当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) Wh...

有没有一种通用的方法来计算for循环的渐近时间复杂度?(Is there a general way to calculate the asymptotic time complexity of for loops with step?)

方法是通过解决复发 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 ...

渐近分析不等式(Asymptotic Analysis Inequalities)

准备工作 上面图像中红色标记部分上方的部分是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 ≤...

函数的渐近分析(Asymptotic analysis of functions)

鉴于, 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 ...

相关文章

更多

chrome如何强制刷新页面?

chrome如何强制刷新页面? F5 ctrl+F5 都没用,总是强制使用页面缓存。

7月最新发布11.2.0.1.2 Patch set update

7月13日,11g release 2 的第二个补丁集更新发布了;9i的最终版本为9.2.0.8,10 ...

redis 字符串(String) SET 操作

命令格式: SET key value 把字符串值value存储到key中。如果存在此key,SE ...

怎么理解Set集合中的HashSet中的元素是无序的?

怎么理解Set集合中的HashSet中的元素是无序的? Set集合中对象是不按特定顺序排序,并且对象 ...

hibernate有两个一对多的Set时怎么写hbm

有两个类,Course和Student,其中Student里面有两个放Course的Set: cla ...

java中list、set和map 的区别(转)

List按对象进入的顺序保存对象,不做排序或编辑操作。Set对每个对象只接受一次,并使用自己内部的排序 ...

Jordan 11 magic reversal

Jordan 11 Columbia Opening, the Magic give the Lake ...

最新问答

更多

如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)

请尝试以下方法: $messages = $user->contact_messages()->paginate(10); Try the following: $messages = $user->contact_messages()->paginate(10);

linux的常用命令干什么用的

linux和win7不一样,win7都图形界面,都是用鼠标来操作打开,解压,或者关闭。而linux是没有图形界面的,就和命令提示符一样的一个文本框,操作linux里的文件可没有鼠标给你用,打开文件夹或者解压文件之类的操作都要通过linux常用命令。

由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)

它创建了这些视图: 'auth/login.blade.php', 'auth/register.blade.php', 'auth/passwords/email.blade.php', 'auth/passwords/reset.blade.php', 'layouts/app.blade.php', 'home.blade.php' 并修改这些文件: 'Http/Controllers/HomeController.php', 'routes/web.php' 如果使用--views

如何交换返回集中的行?(How to swap rows in a return set?)

您可以使用特殊的CASE表达式进行ORDER BY如下所示: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END You can ORDER BY using a special CASE expression like this: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END

在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)

我建议你制作一个新的TableView Cell,在这个newTableViewCell中,加载第2节中的所有单元格,然后为newTableViewCell提供边框。 但如果您不想这样做,那么您可以使用以下代码: @property(strong,nonatomic) CAShapeLayer* borderPath; -(void)viewDidLayoutSubviews{ [_borderPath removeFromSuperlayer]; UIView *viewToGiveBord

使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)

出于一些奇怪的原因,我现在发现了一个不同的问题, Boost.Spirit SQL语法/词法分析失败 ,其中提供了一些其他解决方案来进行空格跳过。 一个更好的! 以下是根据建议重新编写的示例代码: #include #include #include #include #include #incl

Java中的不可变类(Immutable class in Java)

1.如果我只有final变量的课程? 这会让你远离但不是全部。 这些变量的类型也需要是不可变的。 考虑一下 class MyImmutableClass { // final variable, referring to a mutable type final String[] arr = { "hello" }; // ... } 这允许有人做 myImmutableObject.arr[0] = "world"; 并有效地改变你的不可变类的对象。 此外,建议禁

WordPress发布查询(WordPress post query)

如果你想要在div中包含所有帖子: post_parent) { $myposts = get_posts('numberposts=10&tag=medical&order=DESC'); echo ' '; foreach ($myposts as $post): ?>

如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)

我不确定哪个是MySQL的正确答案,因为它本身还不支持IPv6地址格式(尽管“ WL#798:MySQL IPv6支持 ”表明它将在MySQL v6.0中,当前文档不支持)。 不过,你建议的人建议去2 * BIGINT,但要确保他们是UNSIGNED。 在IPv6的/ 64地址边界处有一种自然分割(因为/ 64是最小的网格块大小),这将与其很好地对齐。 I'm not sure which is the right answer for MySQL given that it doesn't y

是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)

您可以使用Object.keys和Array#find来获取匹配value的key 。 const letters = {a:'26',b:'25',c:'24',d:'23',e:'22',f:'21',g:'20',h:'19',i:'18',j:'17',k:'16',l:'15',m:'14',n:'13',o:'12',p:'11',q:'10',r:'9',s:'8',t:'7',u:'6',v:'5',w:'4',x:'3',y:'2',z:'1'}; function sw