JavaScript implements square meters, mu, hectares of unit conversion. You can pass parameters through url to specify that the value of the input box is the value of any unit in the unit.
The source code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Mini-mega, mu, hectare unit conversion applet implemented by javascript</title></head><body><select onchange="selectChange(this)" id="sel"><option value="hectare">hectare</option><option value="mu">mu</option><option value="square meter">square meter</option></select>The value of this input may be 3 hectares, 3 acres, 3 square meters<input type="text" value="3" id="input0"/><script type="text/javascript"> var a = parseInt('0'); ///// Here is a change to the value you receive dynamically. 0 means the unit is square meters, 1 is acre, and 2 is hectares var sel = document.getElementById('sel'); sel.selectedIndex = 2 - a; ////// Set unit pull-down var lastUnit = document.getElementById('sel').value; // Record the current unit var input = document.getElementById("input0"); //10000 square meters = 15 mu = 1 hectares of var fRate = {//Conversion rate hectares: { mu: 15, square meters: 10000 }, mu: { square meters: 10000 / 15, hectares: 1 / 15 }, square meters: { mu: 15 / 10000, hectares: 1 / 10000} }; function selectChange(obj) {//Unit changes, perform conversion var v = parseFloat(input.value);//Get the original value//Please convert, pay attention to the value of fRate, get the last unit node, and then take the conversion rate of the current unit var rst = (v * fRate[lastUnit][sel.value]).toFixed(4);//Retain 4 decimal places input.value = rst; lastUnit = sel.value;//Update the current unit variable}</script></body></html>