[英]Select tag / option tag trouble
因此,大約一個小時后,找不到有關如何使用這些標簽及其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");
}
謝謝您的幫助!
使用jQuery :
var shippingPrice = false;
switch($("#shipMethod").val())
{
case "priority2":
shippingPrice = "3.20";
break;
case "priority3":
shippingPrice = "4.30";
break;
// and so on
}
if (shippingPrice)
$("#shippingChg").val(shippingPrice);
else 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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.