如何在html中维护单个字段的两个值

时间:2022-10-29 13:24:20

I have a requirement, where i need to show rounded decimal value for the fields in the page. But if user doesn't change the field's value then i need to post the original value of field instead of rounded value and my external library will be called with this posted values. For example if a have a field 'Initial Temperature' and its value 12.892433 in database, when i populate the field in the page it will be 12.9. Now if user doesnt change this value then i need to post the actual value which is 12.892433.

我有一个要求,我需要显示页面中字段的舍入小数值。但是如果用户没有更改字段的值,那么我需要发布字段的原始值而不是舍入值,并且将使用此发布的值调用我的外部库。例如,如果a在数据库中有一个字段'Initial Temperature'及其值12.892433,当我填充页面中的字段时它将是12.9。现在,如果用户没有更改此值,那么我需要发布实际值12.892433。

Can anyone suggest me the best way to do this. I dont want to pull data from the database once i have the posted data.

任何人都可以建议我这样做的最佳方法。一旦我有发布的数据,我不想从数据库中提取数据。

1 个解决方案

#1


0  

You can use the data-* attribute, which is used to store custom data private to the page. For example:

您可以使用data- *属性,该属性用于存储页面专用的自定义数据。例如:

<span id="span" data-val="12.892433">12.9</span>

And you can get the value with JS:

你可以用JS获得价值:

var value = $("#span").data("val");

And if you want the value on the server side you can use an input hidden, something like this:

如果你想要服务器端的值,你可以使用隐藏的输入,如下所示:

<input type="hidden" name="value" id="value" value="12.892433">

#1


0  

You can use the data-* attribute, which is used to store custom data private to the page. For example:

您可以使用data- *属性,该属性用于存储页面专用的自定义数据。例如:

<span id="span" data-val="12.892433">12.9</span>

And you can get the value with JS:

你可以用JS获得价值:

var value = $("#span").data("val");

And if you want the value on the server side you can use an input hidden, something like this:

如果你想要服务器端的值,你可以使用隐藏的输入,如下所示:

<input type="hidden" name="value" id="value" value="12.892433">