<select data-placeholder="Please select a payment method.." style="width:50%;" class="chosen" onchange="currencyChange(this.value)">
<option value=""></option>
<optgroup label="Cash">
<option value="Paypal">Paypal</option>
<option value="Bitcoin">Bitcoin</option>
<option value="Western Union">Western Union</option>
<option value="Delivery">Delivery</option>
</optgroup>
<optgroup label="Ingame Currency">
<option value="RS3 GP">RS3 GP</option>
<option value="OSRS GP">OSRS GP</option>
</optgroup>
</select>
<script type="text/javascript">
var sign = "null";
var placement = "null";
float budget = "null";
function currencyChange(data){
if (data === 'Paypal') {
sign = "$";
placement = "before";
}
if (data === 'Bitcoin') {
sign = "$";
placement = "before";
}
if (data === 'Western Union') {
sign = "$";
placement = "before";
}
if (data === 'Delivery') {
sign = "$";
placement = "before";
}
if (data === 'RS3 GP') {
sign = "M/GP";
placement = "after";
}
if (data === 'OSRS GP') {
sign = "M/GP";
placement = "after";
}
if (placement === 'before') {
document.getElementById("budget").value = sign + document.getElementById("budget").value;
}
if (placement === 'after') {
document.getElementById("budget").value = document.getElementById("budget").value + sign;
}
}
</script>
我正在嘗試更改另一個文本字段的貨幣類型id="budget"
,以便根據付款方式的選擇添加貨幣符號。更改文本字段的貨幣類型
但是在選擇付款方式時我沒有收到這樣的動作。
並[小提琴](HTTP ://的jsfiddle。 net/pee7d6qr /)。 – Regent 2014-09-01 12:53:07
好的,語法無效的結構導致函數執行被中止(正如在瀏覽器的控制檯日誌中可以看到的那樣)。該代碼在功能上仍然不正確,因爲更改下拉列表中的選擇會導致添加貨幣符號/縮寫詞,而不會先刪除舊符號/縮寫詞。所以你會得到$$$ 42M/GP。 – 2014-09-01 12:56:06
編輯我的帖子,好心的看看它 – 2014-09-01 13:06:39