去掉 0 和任何非数字字符 Javascript
我如何更改此代码以不允许 0 并删除所有非数字字符?
<script type="text/javascript">
(function() {
var a= document.getElementsByName('a')[0];
var b= document.getElementsByName('b')[0];
var c= document.getElementsByName('c')[0];
a.onchange=b.onchange=a.onkeyup=b.onkeyup= function() {
c.value= Math.ceil((a.value/b.value)*100);
};
})();
</script>
How could I change this code to not allow a 0 and to strip out all non number characters?
<script type="text/javascript">
(function() {
var a= document.getElementsByName('a')[0];
var b= document.getElementsByName('b')[0];
var c= document.getElementsByName('c')[0];
a.onchange=b.onchange=a.onkeyup=b.onkeyup= function() {
c.value= Math.ceil((a.value/b.value)*100);
};
})();
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:更新的答案:
您只需删除所有非非数字,然后测试该数字是否不是 0,然后您就可以执行您的功能。
希望这有帮助。谢谢
如果有的话请告诉我。
PK
EDIT: updated answer:
you simply strip all the non non numbers then test if the number is not a 0 THEN you can perform your function.
Hope this helps. Thanks
Let me know if it does.
PK