How to implement double currency

/*By Jiangong SUN*/


The principe is get the two price at the same place and switch one to another depending on what you want to display.


You can implement it by using ajax and javascript in your asp.net application.



For example, 

Here is the html code you have, and by default you will show your first price. And the you can use a click to a checkbox for switch on/off your double currency.


<div class="double_currency">
	<input type="checkbox" name="double_currency_checkbox" />
</div>
<div class="switch_value">
	<span class="firstPrice">100 euros</span>
	<span class="secondPrice" style="display:none;">100 dollars</span>
</div>


And in your javascript code, you can switch them by using the following code: 

First define a global variable who can be accessed by any place of you application, and assign it null value.


<script type="text/javascript">
    var globalVars = {};
    //define a variable for double currency
    globalVars.doubleCurrencyActivated = null;  


    $(document).ready(function() {
		
		priceClick();
		
        //Update price for double currency
        if (globalVars.doubleCurrencyActivated == true) {
            $("span.firstPrice").css('display', 'none');
            $("span.secondPrice").css('display', 'block');
        }
        else {
            $("span.firstPrice").css('display', 'block');
            $("span.secondPrice").css('display', 'none');
        }
    });
	
	function priceClick() {
		$('.double_currency input:checkbox').bind('click', function() {
			if ($('.double_currency input:checked').length == 1) {
				globalVars.doubleCurrencyActivated = true;
			} else {
				globalVars.doubleCurrencyActivated = false;
			}
		});
	}
</script>

Bad example :


	if ($('.double_device label input:checked', window.parent.document).length == 1) {
		$("#switch_value").text('<span>100 dollars</span>');
	} else { 
		$("#switch_value").text('<span>100 euros</span>');
	}


So I've show you the principe of implementing double currency in javascript.


You can also do it in ajax when you need to update more than just a div.


Enjoy coding!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值