Internet Explorer中的JQuery根本不工作,但在Chrome&火狐

时间:2012-08-23 08:40:05

标签: jquery internet-explorer get

此代码适用于Chrome和Firefox,但不适用于IE8><

 <script src="jquery-latest.js"></script>

 <script type="text/javascript">

    $.get("http://api.hostip.info/get_html.php", function(data){
        alert("Data Loaded: " + data);

    });
 </script>

任何提示?

2 个答案:

答案 0 :(得分:1)

试试这个:

$(document).ready(function(){
    $.get("http://api.hostip.info/get_html.php", function(data){
        alert("Data Loaded: " + data);   
    });
})

答案 1 :(得分:0)

这是另一种方法,它实际上在IE中获取IP:

<script type="text/javascript">
window.onload = function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://jsonip.appspot.com/?callback=DisplayIP";
    document.getElementsByTagName("head")[0].appendChild(script);
};

function DisplayIP(response) {
    document.getElementById("ipaddress").innerHTML = "Your IP Address is " 
                                                      + response.ip;
}
</script>

<span id="ipaddress"></span>