我想弄清楚如何實現這...我有三個下拉選擇列表,每個列表都有自己的值分配。我希望將三個選定值中的最小值/最小值轉換爲隱藏/禁用的文本字段(並且還可以顯示在列表下)。從多個下拉選擇列表中的最小值,如math.min
這裏就是我想要一起工作: -
<select name="Question1" id="Question1" onchange="code(1)">
<option value="10.00" >This is answer A1</option>
<option value="20.00" >This is answer A2</option>
<option value="30.00" >This is answer A3</option>
</select>
<select name="Question2" id="Question2" onchange="code(2)">
<option value="10.00" >This is answer B1</option>
<option value="20.00" >This is answer B2</option>
<option value="30.00" >This is answer B3</option>
</select>
<select name="Question3" id="Question3" onchange="code(3)">
<option value="10.00" >This is answer C1</option>
<option value="20.00" >This is answer C2</option>
<option value="30.00" >This is answer C3</option>
</select>
<input type="text" id="LowestValue" name="LowestValue" onfocus="this.blur()" />
<p>The lowest value is <span>//here should be the lowest of three values</span></p>
所以用戶選擇30.00,30.00和10.00的結果應該是10.00如果是有道理的?
<script>
function code() { // forget the parameter
var Value1 = document.getElementById('Question1');
var Value2 = document.getElementById('Question2');
var Value3 = document.getElementById('Question3');
var LowestValue = document.getElementById('LowestValue');
//I realise this below is wrong but this is essentially what I'm hoping to acheive...
//var total = Math.min(Value1, Value2, Value3);
LowestValue.value = total;
}
</script>
的值是十進制(雙),因爲數值來表示貨幣價值(£10.00)
感謝您的時間:)
爲什麼你認爲這是錯的?它應該工作。 – Bergi 2014-09-24 19:38:30
它只是沒有把值放入文本輸入框...... – will9455 2014-09-24 19:39:20
哦,我現在看到,你的DOM訪問存在一些問題(由@NicolasAlbert完美回答,你應該[接受它](http:// stackoverflow .COM /幫助/人,答案))。但是,將三個數字值傳遞給'Math.min'就像你想要做的那樣。 – Bergi 2014-09-24 19:52:44