How to implement double currency

13 篇文章 0 订阅
10 篇文章 0 订阅
/*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!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值