douhoushou8385 2015-04-02 13:10
浏览 13

根据Geo IP更改Div内容

I currently have a website that is showing a price for a product within a <div>. I would like this number to change if the user is from outside the UK, for example changing the price to Euros rather than GBP.

Is this possible? I can't find an example I understand.

  • 写回答

1条回答 默认 最新

  • dongpao1873 2015-04-02 16:17
    关注

    You should give more example info but Im not going to be so critical.

    You could capture the location using google maps if they agree to it, or ip address and then set a class to all the price divs and price symbol divs.

    try something like this

       <div id="parent_id">
             <div class="item">
                    <span class="symbol">£</span> <div class="price_divs" id="div1">5.00</div>
             </div>
             <div class="item">
                    <span class="symbol">£</span> <div class="price_divs" id="div2">5.00</div>
             </div>
             <div class="item">
                    <span class="symbol">£</span> <div class="price_divs" id="div3">5.00</div>
             </div>
      </div>
    
    
         <script>
    
       jQuery(function(){   ///requires jquery
    
            if(location == "US"){   //location must be a global variable given a value from google maps
    
           var all_pricing = $('#parent_id').find('.price_divs');
    
              $('.symbol').html('$');
    
              $.each(all_pricing,function(x,y){
    
                    var c = convertToDollars($('#'+y.id).html());
                    $('#'+y.id).html(c);
    
              });
    
            }
    
            function convertToDollars(cost)
            {
    
                ///some conversion here
                return cost;
    
            }
    
    
         });
    
          </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测