[英]Multiplying in Javascript
I need to multiply priceMonthly by 30, How can I do that in this "if" function?我需要将 priceMonthly 乘以 30,我该如何在这个“如果”function 中做到这一点? I am using it to echo the entered number live, but I need that number to multiply by 30. Dose someone have over ideas, or can someone guide me why its not working?我正在使用它来实时回显输入的数字,但我需要将该数字乘以 30。有人有过想法,或者有人可以指导我为什么它不起作用?
function keyup_fill(ele, ele_place) {
$(ele).on("keyup", function(event) {
if ( $(ele).attr("name") === "priceMonthly" ) {
if (!$.isNumeric($(ele).val())) {
return ($(ele).val()*30); //not working
}
}
var newText = event.target.value ;
$(ele_place).html(newText);
});
}
keyup_fill("#priceMonthly", "#priceMonthly-place");
If what you want is to show in #priceMonthly-place
the result of multiplying by 30 the value entered in #priceMonthly
you can do this with the code (note that I'm assuming that both ids represent input elements):如果您想要在#priceMonthly-place
中显示将在#priceMonthly
中输入的值乘以 30 的结果,您可以使用代码执行此操作(请注意,我假设两个 id 都代表输入元素):
function keyup_fill(ele, ele_place) {
$(ele).on("keyup", function(event) {
// I'm assuming that `ele` is an input.
var value = $(this).val();
if ($.isNumeric(value)) {
// I'm assuming that ele_place is an input.
$(ele_place).val(value * 30);
}
});
}
keyup_fill("#priceMonthly", "#priceMonthly-place");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.