我已经编写了我的 js 代码,以根据您在所需过滤器类型上选择的下拉选择更改按钮上的 URL,但现在我还需要根据您添加到购物车的数量来更改该 URL。我已经获得了一个功能或另一个功能,但不能同时工作。
绝对欢迎任何建议/帮助!我是 JavaScript 新手。
<script type="text/javascript">
function update_price() {
if ( document.getElementById("filter_menu").value == "1" ){
//this is the first element in the drop down menu. do nothing
document.getElementById("price").innerHTML = "0.00";
document.getElementById("total-price").innerHTML = calculateTotalPrice(0.0, 0.0);
}
if ( document.getElementById("filter_menu").value == "2" ){
// HEPAPure functionality in here.
// don't need to create a new function if you don't want to
document.getElementById("price").innerHTML = "0.00";
document.getElementById("total-price").innerHTML = calculateTotalPrice(599.0, 0.0);
document.getElementById('myLink').href="http://www.mysite.com/cart.asp?product=unit-name&cartitem=unit-name&cartadd=1";
}
if ( document.getElementById("filter_menu").value == "3" ){
// HEPASilver
document.getElementById("price").innerHTML = "10.00";
document.getElementById("total-price").innerHTML = calculateTotalPrice(599.0, 10.0);
document.getElementById('myLink').href="http://www.mysite.com/cart.asp?product=unit-name-silver&cartitem=unit-name-silver&cartadd=1";
}
if ( document.getElementById("filter_menu").value == "4" ){
// HEPAFreshPlus
document.getElementById("price").innerHTML = "20.00";
document.getElementById("total-price").innerHTML = calculateTotalPrice(599.0, 20.0);
document.getElementById('myLink').href="http://www.mysite.com/cart.asp?product=unit-name-freshplus&cartitem=unit-name-freshplus&cartadd=1";
}
if ( document.getElementById("filter_menu").value == "5" ){
// HEPAOdorCell
document.getElementById("price").innerHTML = "30.00";
document.getElementById("total-price").innerHTML = calculateTotalPrice(599.0, 30.0);
document.getElementById('myLink').href="http://www.mysite.com/cart.asp?product=unit-name-odorcell&cartitem=unit-name-odorcell&cartadd=1";
}
}
function calculateTotalPrice(unitPrice, price){
var total = unitPrice + price;
return total;
}
function update_URL(){
if ( document.getElementById("quantity_top").value == "cartadd2" ){
// HEPAOdorCell
document.getElementById('myLink').href="http://www.mysite.com/cart.asp?product=unit-name-odorcell&cartitem=unit-name-odorcell&cartadd=2";
}
}
</script>