非常感谢大家的帮助 - 非常感谢。
但是,我接下来要做的事情真的很复杂,我相信你们有头脑来帮助我。
这是我也想以更好的方式编写的更复杂的代码——更少的代码,更高效。
抱歉,这是很多代码。
JS:
function keyTechAdoption() {
var keyTechBox = document.getElementById('keyTechTextBox');
var sVOption = document.getElementById("dropdown_serverVirtualisation");
var sV_Value = 10;
var dVOption = document.getElementById("dropdown_desktopVirtualisation");
var dV_Value = 20;
// Server Virtualisation Value ----------------------------------------------------------------------------------------- //
if (sVOption.options[sVOption.selectedIndex].value === "N") {sV1 = null; sV2 = 0;}
if (sVOption.options[sVOption.selectedIndex].value === "G") {sV1 = sV_Value * 1; sV2 = sV_Value * 1;}
if (sVOption.options[sVOption.selectedIndex].value === "O") {sV1 = sV_Value * 0.3; sV2 = sV_Value * 1;}
if (sVOption.options[sVOption.selectedIndex].value === "A") {sV1 = sV_Value * 0.5; sV2 = sV_Value * 1}
if (sVOption.options[sVOption.selectedIndex].value === "R") {sV1 = 0; sV2 = sV_Value * 1;}
else if (sVOption.options[sVOption.selectedIndex].value === "U") {sV1 = 0; sV2 = sV_Value * 1;}
// Server Virtualisation Value ----------------------------------------------------------------------------------------- //
// Desktop Virtualisation Value ----------------------------------------------------------------------------------------- //
if (dVOption.options[dVOption.selectedIndex].value === "N") {dV1 = null; dV2 = 0;}
if (dVOption.options[dVOption.selectedIndex].value === "G") {dV1 = dV_Value * 1; dV2 = dV_Value * 1}
if (dVOption.options[dVOption.selectedIndex].value === "O") {dV1 = dV_Value * 0.3; dV2 = dV_Value * 1;}
if (dVOption.options[dVOption.selectedIndex].value === "A") {dV1 = dV_Value * 0.5;dV2 = dV_Value * 1}
if (dVOption.options[dVOption.selectedIndex].value === "R") {dV1 = 0; dV2 = dV_Value * 1;}
else if (dVOption.options[dVOption.selectedIndex].value === "U") {dV1 = 0; dV2 = dV_Value * 1;}
// Desktop Virtualisation Value ----------------------------------------------------------------------------------
var keyTechTotal1 = sV1 + dV1;
var keyTechTotal2 = sV2 + dV2;
var keyTechPercentage = (keyTechTotal1) / (keyTechTotal2) * 100
if (keyTechTotal1 > 0) {keyTechBox.value = keyTechPercentage.toFixed(0) + "%";}
else {keyTechBox.value = 0 + "%";}
}
HTML:
<input class="textBox" runat="server" type="text" id="keyTechTextBox" readonly="true" />
<select class="selectElement" runat="server" id="dropdown_serverVirtualisation" onchange="keyTechAdoption()">
<option value="N">N</option>
<option value="G">G</option>
<option value="O">O</option>
<option value="A">A</option>
<option value="R">R</option>
<option value="U">U</option>
</select>
<select class="selectElement" runat="server" id="dropdown_desktopVirtualisation" onchange="keyTechAdoption()">
<option value="N">N</option>
<option value="G">G</option>
<option value="O">O</option>
<option value="A">A</option>
<option value="R">R</option>
<option value="U">U</option>
</select>
我不能感谢你们这些了不起的人的帮助和时间:)