gpt4 book ai didi

javascript - 选择标签/选项标签问题

转载 作者:行者123 更新时间:2023-11-28 10:33:38 26 4
gpt4 key购买 nike

因此,大约一个小时后,无法找到关于如何使用这些标签及其 id、名称和值来实现小数金额以完成对我的表单求和的良好教程。简而言之,我有一个选择框,希望它返回我的选项值和该选项值的金额。

这是 HTML

<tr>
<th colspan="4" class="label">Shipping Method:
<select name="shipMethod" id="shipMethod" size="1">
<option value="">Choose a shipping method</option>
<option value="priority2">Priority mail $3.20 (4 items or less)</option>
<option value="priority3">Priority mail $4.30 (6 items or less)</option>
<option value="priority4">Priority mail $5.40 (8 items or less)</option>
<option value="overnight">Express $15.75 (4 items or less only)</option>
<option value="UPS">UPS - 2 day $15.00 (9 - 49 items)</option>
<option value="free">Free shipping (50+ items only)</option>
</select>
</th>
<td><input name="shippingChg" id="shippingChg" type="text" size="10" maxlength="60" value="" /></td>
</tr>
<tr>

我的第一个问题可能是为小数点设置一个循环。这就是我尝试为一个选择框编写循环和函数的方式

 function ship_some_stuff()
var ship_me= document.getElementById("shipMethod").value; (unsure if this returns
the option value though, but the idea is to save to a variable later)

if ship_me == priority2 {
var shipthisway = 3.20;
document.getElementById("shippingCHg").value = varshipthisway ;
}

if ship_me == priority3{
var shipthisway = 4.30;
document.getElementById("shippingCHg").value = varshipthisway ;
}


else varship == ""; {
alert("You haven't selected a shipping Method");
}

感谢您的帮助!

最佳答案

function get_shipping_charge() { 
var ship_me= document.getElementById("shipMethod").value;
if (ship_me == "priority2") return 3.20;
else if (ship_me == "priority3") return 4.30;
else return NaN;
}
function do_shipping_charge() {
var shipthisway = get_shipping_charge();
if (shipthisway) document.getElementById("shippingCHg").value = shipthisway;
else alert("You haven't selected a shipping Method");
}

关于javascript - 选择标签/选项标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2275298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com