我在这里复制/粘贴Bing基础教程中的脚本:Bing basic API
我已在Dreamweaver中粘贴示例脚本:
<script type="text/javascript">
function search() {
var search = "&query=" + document.getElementById("searchText").value;
var fullUri = serviceURI + AppId + search;
var head = document.getElementsByTagName('head');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = fullUri;
head[0].appendChild(script);
}
function searchDone(results) {
var result = null;
var parent = document.getElementById('resultList');
parent.innerHTML = '';
var child = null;
for (var i = 0; i < results.SearchResponse.Image.Results.length; i++) {
result = results.SearchResponse.Image.Results[i];
child = document.createElement('li');
child.className = "resultlistitem";
child.innerHTML = '<a href="' + result.Url +'"><img src="' +
result.Thumbnail.Url +'" alt="' + result.Title +'" /></a>';
parent.appendChild(child);
}
}
var AppId = "&Appid=86F7F70727A6D88CCE422ED44905A378E9780D81";
var serviceURI = "http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sourc
es=image";
</script>
Dreamweaver告诉我这里有问题:
var serviceURI = "http://api.bing.net/json.aspx?JsonType=callback&JsonCallback=searchDone&sourc
es=image";
我也把脚本放在JsBin上进行调试,但是Jsbin告诉我脚本很好..我不知道问题是什么,因为脚本在浏览器中不起作用
答案 0 :(得分:2)
根据您发布的代码,Dreamweaver似乎是正确的。如果要将字符串换行到JavaScript中的第二行,则需要执行以下两项操作之一:
var serviceURI = "http://api.bing.net/json.aspx?sonType=callback&JsonCallback" +
"=searchDone&source=image";
或者
var serviceURI = "http://api.bing.net/json.aspx?sonType=callback&JsonCallback \
=searchDone&source=image";