javascript - JQuery 脚本在 JSFiddle 中有效,但在我自己的浏览器中无效

标签 javascript jquery html json

正如标题所说... 尝试更改 JQuery 版本。尝试了不同的浏览器(Mozilla、Chrome、Opera、IE)。还尝试从我自己的服务器加载 JQuery 库。没有任何运气。请帮帮我。

在这里,代码在 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>

最佳答案

脚本元素不能有 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

The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI. Note that the charset attribute refers to the character encoding of the script designated by the src attribute; it does not concern the content of the SCRIPT element.

关于javascript - JQuery 脚本在 JSFiddle 中有效,但在我自己的浏览器中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20851005/

相关文章:

javascript - Selenium 中通过 jQuery 生成获取元素

javascript - 如何为用户创建多个相同表单

javascript - 如何在 javascript 中访问嵌套的 html-child 元素

javascript - 使用 jquery Draggable UI 使项目可拖动

javascript - 禁用使用 &lt;script&gt; 标签加载的特定 JavaScript

javascript - 没有模板引擎的 Node View 传递的数据

javascript - jQuery/JS 包含运算符或类似的

javascript - 复选框:jQuery 必需功能

带有原型(prototype)的 JavaScript 继承—— 'constructor' 属性?

javascript - 隐藏表行时使用 rowspan 处理单元格