-3

我将在 html 页面中添加 jquery json 数据的位置。所有 HTML 页面组件都消失了,只在页面左上方显示 json 数据:

$.getJSON('http://api.wipmania.com/jsonp?callback=?', 
    function (data) { 
        document.write('Latitude: ' + data.latitude + '\nLongitude: ' + data.longitude + '\nCountry: ' + data.address.country); 
    }
); 
4

1 回答 1

1

阅读文档document.write()我们发现:

将文本字符串写入由 document.open(). [...]
写入已加载但未调用的文档document.open()将自动执行 document.open调用

...和文档document.open()

document.open() 方法打开一个文档进行写入。[...]
如果目标中存在文档,则此方法将其清除

使用document.write()注入原始 HTML 可能是创建动态文档最烦人的工具。您正在使用 jQuery——利用它的 DOM 操作工具。

于 2012-12-31T10:05:47.243 回答