日期:2014-05-16 浏览次数:20374 次
<html> <meta charset="gbk" /> <title>词语关联度查询与投票</title> <head> <script type="text/javascript"> function vote(str) { var xmlhttp1; var rs=document.getElementById(str); if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp1=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp1.open("GET","insert.php?query="+str,true); alert("Succeed!"); rs.innerHTML=parseInt(rs.innerHTML)+1; xmlhttp1.send(null); return true; } function found(str) { var query=document.getElementById("word"); var wait=document.getElementById("blank"); wait.innerHTML="Waiting......"; if (str.length==0) { wait.innerHTML=""; return true; }; var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { //alert(xmlhttp.status); //alert(xmlhttp.readyState); if (xmlhttp.readyState==4) { if (xmlhttp.status==200) { wait.innerHTML=""; var words=eval("("+xmlhttp.responseText+")"); var newtable = document.createElement("table"); //下面这句话出了问题,有报错,报错信息详见下方 newtable.innerHTML="<tr><td width = \"100\">ID</td><td width=\"100\">词语1</td><td width = \"100\">词语2</td><td width = \"100\">相关度</td><td width = \"100\">票数</td><td width=\"100\">投票</td></tr>"; for (var i in words) { var tr=document.createElement("tr"); var id_td=document.createElement("td"); id_td.innerHTML=words[i].id; tr.appendChild(id_td); var word1_td=document.createElement("td"); word1_td.innerHTML=words[i].word1; tr.appendChild(word1_td); var word2_td=document.createElement("td"); word2_td.innerHTML=words[i].word2; tr.appendChild(word2_td); var relation_td=document.createElement("td"); relation_td.innerHTML=words[i].relation; tr.appendChild(relation_td); var number_td=document.createElement("td"); number_td.innerHTML="<div id='"+words[i].id+"'>"+words[i].num+"</div>"; tr.appendChild(number_td); var vote_td=document.createElement("td"); vote_td.innerHTML="<form> <input type='button' value='vote' onclick='vote("+words[i].id+")' /> </form>" tr.appendChild(vote_td); newtable.appendChild(tr); } wait.innerHTML = ""; wait.appendChild(newtable); } else { wait.innerHTML="Connection Failed";} } } xmlhttp.open("GET","search.php?query="+str,true); xmlhttp.send(null); return true; } </script> </head> <body bgcolor="pink" text="red"> <center> <h1