javascript - 更改文本字段货币类型

标签 javascript php jquery html

<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"的货币类型,以根据选择的付款方式添加货币符号..?

但在选择付款类型时我没有收到此类操作。

最佳答案

删除这个,它的作品

float budget = "null";

并且,

添加下面的选择

<input type="text" id="budget">

已编辑

        if (placement === 'before') {                
            toreplaceaft=document.getElementById("budget").value;   
            toreplacebef=toreplaceaft.replace("$","");
            toreplace=toreplacebef.replace("M/GP","");
            document.getElementById("budget").value = sign + toreplace.replace("$","");
        }

        if (placement === 'after') {     
            toreplaceaft=document.getElementById("budget").value;   
            toreplacebef=toreplaceaft.replace("$","");
            toreplace=toreplacebef.replace("M/GP","");
            document.getElementById("budget").value =  toreplace+ sign;                                                            
        }

关于javascript - 更改文本字段货币类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25606150/

相关文章:

javascript - CSS 中的滑动门动画,如 Twitter 通知

php - 403 禁止在工作模式下使用 php。仅来自浏览器的 php 文件

javascript - 检查页面是否在 Google Chrome 的 Iframe 中

javascript - 类型错误 : 'undefined' is not a function in Safari

javascript - Youtube Javascript API 播放();不工作..我做错了什么?

php - 仅通过电子邮件中单击的链接对用户进行身份验证

PHP & MySQL - 从数据库中的整数生成发票编号

javascript - 使用 jQuery 或 CSS 更改 Android 键盘的方向

javascript - 在第一个动画之后调用它后,div 上的动画不起作用?

javascript - 不变违规 : requireNativeComponent: "BVLinearGradient"