- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
似乎无法将 Not a Number NaN
错误替换为 0
。尝试使用 rapply
但对我不起作用。
window.onload = function () {
var first = document.getElementById('firstFieldId'),
second = document.getElementById('secondFieldId'),
third = document.getElementById('thirdFieldId'),
fourth = document.getElementById('fourthFieldId');
first.onkeyup = function () {
var value;
// Get the value and remove the commas
value = first.value.replace(/,/g, "");
// Make it a number
value = parseInt(value, 10);
// Add one to it
++value;
// Turn it back into a string
value = String(value);
// Put it in the other text box, formatted with commas
second.value = numberWithCommas(value);
};
third.onkeyup = function () {
var value;
// Get the value and remove the commas
value = third.value.replace(/,/g, "");
// Make it a number
value = parseInt(value, 10);
// Add one to it
++value;
// Turn it back into a string
value = String(value);
// Put it in the other text box, formatted with commas
fourth.value = numberWithCommas(value);
};
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
};
做了一个 JSFiddle http://jsfiddle.net/7r5SF/2/ - 如果您在第一个或第三个字段中输入一个数字,然后清除它,第二个或第四个字段将显示为 NaN
...它需要说 0
!
任何帮助都会很棒!
最佳答案
关于javascript - 无法将 NaN 替换为 0 - 尝试了 rapply,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895730/
要跟进两个 rapply 问题,here和 here从几年前开始,rapply 似乎只适用于简单的类(即向量、矩阵),而不适用于多方面的 data.frame 类。 在大多数情况下以及下面的演示中,r
我可以使用rapply深入了解列表(其结构未知;可能嵌套也可能不嵌套)以提取一些信息吗?例如,我有一个模型对象列表,其中一个元素也是模型对象列表。我可以同时运行一个函数吗? df getcoef
我有一个嵌套列表,其基本元素是数据帧,我想递归地遍历这个列表来对每个数据帧进行一些计算,最后得到一个与输入结构相同的嵌套结果列表。我知道“rapply”正是针对此类任务,但我遇到了一个问题,rappl
似乎无法将 Not a Number NaN 错误替换为 0。尝试使用 rapply 但对我不起作用。 window.onload = function () { var first = do
我知道列表中的 NULL 值有时会 trip人起来。我很好奇为什么在特定情况下 lapply和 rapply好像对待NULL值(value)观不同。 l lapply(NULL, identity)
我是一名优秀的程序员,十分优秀!