非常感謝所有人的幫助 - 非常感謝。使用html選項指定javascript變量
但是,接下來我想要做的事情非常複雜,我相信你們都有能力幫助我。
這是更復雜的代碼,我也想寫一個更好的方式 - 更少的代碼,更高效。
對不起,但這是很多代碼。
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>
我不知道怎麼感謝你讓人歎爲觀止足夠的幫助和時間:)
那麼首先,乘以1不d任何事情。來自哪些神奇數字? – thatidiotguy
@thatidiotguy乘以1會將一個字符串轉換爲一個數字,但不適用,因爲'select1_control'是'10' – Ian
@thatidiotguy謝謝 - 這很有道理 - 爲什麼我甚至有它在那裏 – Singh