2016-06-05 10 views
0

GEO DIV, So fügen Sie sonst zeigen {# other-Land},
Helfen Sie mir hinzuzufügen, bitte .......
ausblenden CN und HK, wenn die ip andere ist geo div wie sonst show # andere Land

<html> 
 

 
<head> 
 
    <script type="text/javascript" src="jquery-1.11.0.min.js"></script> 
 
    <style> 
 
    #CN { 
 
     text-align: left; 
 
     color: blue; 
 
     display: none; 
 
    } 
 
    #HK { 
 
     text-align: left; 
 
     color: blue; 
 
     display: none; 
 
    } 
 
    #country_code { 
 
     text-align: left; 
 
     color: blue; 
 
     display: none; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 

 
    <div id="HK">Hello HK</div> 
 
    <div id="CN">hello China</div> 
 
    <div id="other-country">Hello Other country</div> 
 
    <script> 
 
    $.get("http://freegeoip.net/json/", function(response) { 
 
     $("#country_code").html(response.country_code); 
 
     if (response.country_code == 'HK' || response.country_code == 'CN') { 
 
      document.getElementById(response.country_code).style.display = "block"; 
 
     } 
 

 
     } 
 

 
     , "jsonp"); 
 
    </script> 
 
</body> 
 

 
</html>

andere quenstion,
kann dies steckt es in meinem eigenen Server?
http://freegeoip.net/json/

Antwort

0

Geben Sie alle Ländercode div eine gemeinsame Klasse.

<div id="HK" class="country-code">Hello HK</div> 
<div id="CN" class="country-code">hello China</div> 
<div id="other-country" class="country-code">Hello Other country</div> 

$.get("http://freegeoip.net/json/", function(response) { 
    $("#country_code").html(response.country_code); 
    document.querySelectorAll(".country-code").style.display = "none"; 
    if (response.country_code == 'HK' || response.country_code == 'CN') { 
     document.getElementById(response.country_code).style.display = "block"; 
    } 
    else{ 
     document.getElementById('other-country').style.display = "block"; 
    } 

    } 

    , "jsonp"); 
0

Betreffend in @Prs Antwort - Gerade gesehen, Ihre Post nach "Hantieren" mit einer ähnlichen Idee :)

https://jsfiddle.net/kendrikat/b9hp434q/1/

HTML:

Hello 
<div id="HK" class="country_code">HK</div> 
<div id="DE" class="country_code">Germany</div> 
<div id="OTHER" class="country_code">Other Country</div> 

CSS:

.country_code { 
    text-align: left; 
    color: blue; 
    display: none; 
} 

JS:

var countries_to_highlight = ['DE', 'HK']; 

// hide them all - while loading 
showCountry('', false) 

$.get("https://freegeoip.net/json/", function(response) { 

    if (countries_to_highlight.indexOf(response.country_code) > -1) { 
    showCountry(response.country_code, true); 
    showCountry('OTHER', false); 
    } else { 
    showCountry('OTHER', true); 
    $('#OTHER.country_code').html(response.country_code); 
    } 

}, "jsonp"); 

function showCountry(tag, show) { 
    $((tag.length > 0 ? '#' + tag : '') + '.country_code').css('display', show ? 'inline' : 'none') 
} 

Sie zweite Frage betrifft, ob Sie berechtigt sind, es auf Ihrem eigenen Server ausführen:

Der freegeoip Web-Server ist kostenlos und Open Source also, wenn der öffentliche Dienst Grenze a Problem für Sie, laden Sie es herunter und führen Sie Ihre eigene Instanz.

Aus ihrer Hauptseite