2016-09-29 147 views

回答

0

不知道你在找什麼。這可能是基於ypur問題描述的解決方案。

var itemCost = 10; //Nor directly retrivable from HTML 

var shipSelect = document.getElementById('selectbasic'); 
var shipCost = shipSelect[shipSelect.selectedIndex].value *1; 

var rewards = 0; 
var checkBox = document.getElementById('checkboxes-0'); 
if (checkBox.checked) { 
    rewards = checkBox.value * 1; 
} 

if (rewards> (itemCost + shipCost)) { 
    rewards = itemCost + shipCost; 
} 

alert('Item price: ' + itemCost + 
    '\nShipping: ' + shipCost + 
    '\nRewards: ' + rewards + 
    '\nTotal: ' + (itemCost + shipCost - rewards));