根据国家/地区更改横幅

问题描述 投票:0回答:1

如果国家是印度,并且我要显示srilanka.jpg是国家是斯里兰卡,我想显示india.jpg。

这检测到我的国家

alert("Your location is: " + geoplugin_countryName() + ", " + geoplugin_region() + ", " + geoplugin_city());

印度地理代码:22.512557,80.076350SL的地理位置代码:7.460518,80.783469

如何动态显示?请帮助

Js小提琴-http://jsfiddle.net/madhuri2987/KS4yy/2/

javascript jquery google-maps geolocation detect
1个回答
1
投票

以下是基于您的代码的一般想法。创建图像,检查国家/地区名称,并适当更改图像的src属性。

jQuery( document ).ready( function( $ ) {
    var image = document.createElement('img'),
        country = geoplugin_countryName();
    if ( country === 'India' ) {
        image.src = 'location/of/image/india.jpg'
    } else if ( country === "Sri Lanka" ) {
        image.src = 'location/of/image/sri-lanka.jpg';
    } else {
        image.src = 'location/of/image/default.jpg';
    }
    $('#flag').html( image );
});

完整代码:http://jsfiddle.net/KS4yy/7/

© www.soinside.com 2019 - 2024. All rights reserved.