简体   繁体   English

JQuery脚本在JSFiddle中工作,但不在我自己的浏览器中

[英]JQuery script works in JSFiddle, but doesn't in my own browser

As the title says... Tried changing the JQuery vesion. 正如标题所说......尝试改变JQuery vesion。 Tried different browsers (Mozilla, Chrome, Opera, IE). 尝试过不同的浏览器(Mozilla,Chrome,Opera,IE)。 Also tried loading the JQuery library from my own server. 还尝试从我自己的服务器加载JQuery库。 Haven't had any luck. 没有运气。 Help me out, please. 请帮帮我。

Here, the code works in JSFiddle... http://jsfiddle.net/GUuNG/ 这里,代码在JSFiddle中运行... http://jsfiddle.net/GUuNG/

<!DOCTYPE html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">

$(document).ready(function(){
    $("button").click(function(){
    $.getJSON("https://prod.api.pvp.net/api/lol/euw/v1.1/summoner/by-name/krepo?api_key=b05c2251-f659-4d24-8b5f-6b25a482b42a"  , function(result){
            $.each(result, function(key, value){
            $("div").append("<b>" +key+"--"+value +"</b><br/>");
            });
        });
    });
});
</script>
</head>
<body>
<button>Get Json Data</button>
<div></div>
</body>
</html>

You cannot have the src and body for a script element 你不能拥有脚本元素的src和body

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
    $.getJSON("https://prod.api.pvp.net/api/lol/euw/v1.1/summoner/by-name/krepo?api_key=b05c2251-f659-4d24-8b5f-6b25a482b42a"  , function(result){
            $.each(result, function(key, value){
            $("div").append("<b>" +key+"--"+value +"</b><br/>");
            });
        });
    });
});
</script>

HTML4 HTML4

The script may be defined within the contents of the SCRIPT element or in an external file. 脚本可以在SCRIPT元素的内容中定义,也可以在外部文件中定义。 If the src attribute is not set, user agents must interpret the contents of the element as the script. 如果未设置src属性,则用户代理必须将该元素的内容解释为脚本。 If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI. 如果src具有URI值,则用户代理必须忽略该元素的内容并通过URI检索脚本。 Note that the charset attribute refers to the character encoding of the script designated by the src attribute; 注意,charset属性是指src属性指定的脚本的字符编码; it does not concern the content of the SCRIPT element. 它与SCRIPT元素的内容无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM