-1
如何刷新您的結果時,讓你搜索任何關鍵字。如果我使用innerHTML,它可以更新我找到的關鍵字,但是當使用腳本src時我不起作用,它只能工作一次。這是我的編碼刷新JavaScript Src
<html>
<head>
<title>Google Search API</title>
</head>
<body>
<div id="box">
<textarea id="myTextarea"></textarea>
<button type="button" id="mySubmit" onclick="myFunction()" >Search</button>
<p id="demo"></p>
<div id="content">
</div>
<script id="searchme"></script>
<script>
function myFunction() {
var query = document.getElementById("myTextarea").value;
var search_query = "https://www.googleapis.com/customsearch/v1?q="+query+"&cx=004123968310343535430%3Aaxml6iel9yo&key=AIzaSyDxPcphnrcN9_dfkRkFTbwkv44m1-HI1Hg&callback=hndlr";
document.getElementById('searchme').src = search_query;
}
function hndlr(response) {
for (var i = 0; i <response.items.length; i++) {
var item = response.items[i];
document.getElementById("content").innerHTML +="<br>"+"<b>"+ item.title + "</b>"+"<br>" +item.snippet + "<br>"+"<a href='"+item.link+"'>"+item.displayLink+"</a>" ;
}
}
</script>
</body>
</html>
它不工作,遇到錯誤 – Rushdiey
顯示我的錯誤 –
遺漏的類型錯誤:在HTMLTextAreaElement.onkeydown :無法讀取性能在myFunction的(22 jquery3.php)空 的「價值」(jquery3.php:8) – Rushdiey