更新跨度没问题,更新输入结果为“NaN”;
我正在使用 jquery 和 php 脚本转换价格,该脚本从 Yahoo! 获取最新汇率。
我的更新函数正在处理可以使用 .text() 更新的元素(例如 span 元素),但是一旦我尝试设置输入元素的 .val() ,它就会简单地收到“NaN” - 即使我“ m 两者使用相同的值。
function frmtCurrency(ele,price) {
// round the currency to the nearest .05
price *= 2.0;
price = price.toFixed(1) / 2.0;
price = price.toFixed(2);
//alert (parseInt(price)) here returns the amount, so it IS a number
// check what type of element 'ele' is
var element = (ele.get(0).tagName);
if (element != 'INPUT') {
ele.text(price+code); ALWAYS OK eg 10.55
} else {
ele.val(price); // ALWAYS NaN
}
};
谁能告诉我为什么我无法更新输入字段但我可以更新 span 元素
I'm converting prices using jquery and a php script that pulls in the latest exchange rate from Yahoo!
My update function is working on elements that I can update with .text() (eg span elements) but as soon as I try to set the .val() of my input element, it simple receives 'NaN' - even though I'm using the same value for both.
function frmtCurrency(ele,price) {
// round the currency to the nearest .05
price *= 2.0;
price = price.toFixed(1) / 2.0;
price = price.toFixed(2);
//alert (parseInt(price)) here returns the amount, so it IS a number
// check what type of element 'ele' is
var element = (ele.get(0).tagName);
if (element != 'INPUT') {
ele.text(price+code); ALWAYS OK eg 10.55
} else {
ele.val(price); // ALWAYS NaN
}
};
Can anyone tell me why I can't update an input field but I can update a span element
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很可能您在软件中的某个时刻传递了一个字符串或错误的内容,从而给您一个 NaN。在这里您可以看到我传递了一个空字符串,并添加了一个句柄,使其在未给出实数时显示为 0.00。
http://jsfiddle.net/kuroir/DaHSA/1/
Odds are you're passing a string or something wrong at some point in your software, giving you a NaN. Here you can see I pass a empty string and I add a handle to make it appear as a 0.00 when no real number is given.
http://jsfiddle.net/kuroir/DaHSA/1/