Javascript 将动态多表单字段解析为浮动
我想用一个特定的类来解析输入字段。但是,只有第一个字段的值被解析并复制到其他字段Javascript 将动态多表单字段解析为浮动,javascript,jquery,Javascript,Jquery,我想用一个特定的类来解析输入字段。但是,只有第一个字段的值被解析并复制到其他字段 请注意,这些字段是动态的,这就是我无法使用特定ID的原因。如果我这样做,我可能不得不重新编写javascript代码 简而言之,您需要使用当前值: $(document).ready(function(){ // collects all elements with the class test $('.test').focusout(function(e) { // foreach
请注意,这些字段是动态的,这就是我无法使用特定ID的原因。如果我这样做,我可能不得不重新编写javascript代码 简而言之,您需要使用当前值:
$(document).ready(function(){
// collects all elements with the class test
$('.test').focusout(function(e) {
// foreach element in this collection do the following
// get the current value
var value = $(this).val();
if(value) {
value = parseFloat(value).toFixed(2);
// update if required
$(this).val(value);
}
});
});
简而言之,您需要使用当前值:
$(document).ready(function(){
// collects all elements with the class test
$('.test').focusout(function(e) {
// foreach element in this collection do the following
// get the current value
var value = $(this).val();
if(value) {
value = parseFloat(value).toFixed(2);
// update if required
$(this).val(value);
}
});
});
获取匹配元素集中第一个元素的当前值,或设置每个匹配元素的值。这就是为什么它只解析第一个输入获取匹配元素集中第一个元素的当前值或设置每个匹配元素的值。这就是为什么它只解析第一个输入,耶稣基督。我以为伊玛会做一些疯狂的巫术。谢谢天哪。我以为伊玛会做一些疯狂的巫术。谢谢
$(document).ready(function(){
// collects all elements with the class test
$('.test').focusout(function(e) {
// foreach element in this collection do the following
// get the current value
var value = $(this).val();
if(value) {
value = parseFloat(value).toFixed(2);
// update if required
$(this).val(value);
}
});
});