同时在用hbuilder测试时,一直显示xmlpz=shiyun.XMLDocument.documentElement;代码出错。这么久,都将html忘得差不多了,现在想烦请高手看一下,这些代码哪些地方要做修改。
源码很多,字数限制,便将拼音数据那一部份节选,以下是部份代码:
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<title></title>
<style>
body {
SCROLLBAR-FACE-COLOR: #E7E9EE; SCROLLBAR-HIGHLIGHT-COLOR: #E7E9EE;
SCROLLBAR-SHADOW-COLOR: #000000; SCROLLBAR-DARKSHADOW-COLOR: #ffffff;
SCROLLBAR-3DLIGHT-COLOR: #ffffff; SCROLLBAR-ARROW-COLOR: #234567;
SCROLLBAR-TRACK-COLOR: #F8F9FD;
}
.htable{border-left:1px solid #000000;border-top:1px solid #000000;border-right:0px;border-bottom:0px}
.htd{border-right:1px solid #000000;border-bottom:1px solid #000000}
.ddiv {font-family:楷体_GB2312;font-size:30;position:absolute;top:0;left:0;color:#E6005C;font-weight:bold;z-index:1;width:100%;height:100%}
.ddivp {font-family:楷体_GB2312;font-size:30;position:absolute;top:0;left:0;color:#87CEFA;font-weight:bold;z-index:1;width:100%;height:100%}
.ddivz {font-family:楷体_GB2312;font-size:30;position:absolute;top:0;left:0;color:#228B22;font-weight:bold;z-index:1;width:100%;height:100%}
.ddivpz{font-family:楷体_GB2312;font-size:30;position:absolute;top:0;left:0;color:#4D3900;font-weight:bold;z-index:1;width:100%;height:100%}
.cdiv{position:relative;width:100%;height:100%}
.ai {font-size:15pt; color:#234567; height:150px;width:330px;font-family: 隶书;overflow-y:auto;font-weight:bold }
.test{position:relative;text-decoration:none;}
.test:hover{background:none;}
.test span {display: none;}
.test:hover span{display:block;position:absolute;top:15px;left:1px;border-bottom:2px solid #F3F3F3;border-right:1px solid #F3F3F3;width=130}
.test:hover span p{border:2px solid #EAEAEA;background:#FFFFF0;color:#4d1f00;padding:3px;text-align:left;font-size:13px;}
.chen{font-size:15pt;color:ff0000;font-weight:bold}
</style>
<script language=javascript >
var help="点击此处便可输入汉字进行查询\r\n";
function getPath(ch){
var ns=xmlpz.selectNodes('//yun[contains(text(),"'+ch+'")]');
var res="";
for(var i=0;i<ns.length;i++){
if(i>0)
res+="<br>";
var n=ns[i].parentNode;
var nt=n.getAttribute("type");
// alert(nt);
if(nt=="阴平" || nt=="阳平" || nt=="轻声")
res+="";
else
res+="";
res+=nt+"〖<font class=chen>"+ns[i].getAttribute("type")+"</font>〗";
}
return res;
}
function getPingZe(ch){
var ns=xmlpz.selectNodes('//yun[contains(text(),"'+ch+'")]');
var res=0;
for(var i=0;i<ns.length;i++){
var n=ns[i].parentNode;
var nt=n.getAttribute("type");
if(nt=="阴平" || nt=="阳平" || nt=="轻声")
res |= 1;
else
res |=2;
}
return res;
}
function getWordFmt(ch,bOnlyPZ){
var fh="!,;:.?'\",;:。?“”’‘! \r\t";
var x="<a href='#' class='test'><div class=cdiv><div class=";
if(fh.indexOf(ch)>=0)
return x+"ddiv>"+ch+"</div></div>";
var pz=getPingZe(ch);
var pzclass=new Array("ddiv","ddivp","ddivz","ddivpz");
x+=pzclass[pz]+">"+ch+"</div>";
if(bOnlyPZ)
return x+"</div>";
return x+"</div><span><p>"+getPath(ch)+"</p></span></a>";
}
function getWordTd(ch,bOnlyPZ){
return "<td width=35px class=htd>"+getWordFmt(ch,bOnlyPZ && ! chkAll)+"</td>";
}
function getFmtJu(st,lMaxLen){
var res="<tr height=35px>";
for(var i=0;i<st.length;i++)
res+=getWordTd(st.substr(i,1),(i!=st.length-1));
for(var i=st.length;i<lMaxLen;i++)
res+=getWordTd(" ",false);
return res+"</tr>";
}
function getFmtShiCi(dl){
dl=dl.replace(/([ ])?/g,"");
dl=dl.replace(/[==]{2,}/g,"\r\n");
dl=dl.replace(/[,;:.?!,;:。?!]/g,"\r\n");
dl=dl.replace(/(\r\n){2,}/g,"\r\n");
var aa=dl.split("\r\n");
var iMax=0;
var res="<table border=0 class=htable>";
for(var i=0;i<aa.length;i++)
if(iMax<aa[i].length)
iMax=aa[i].length;
for(var i=0;i<aa.length;i++)
if(aa[i] != "")
res+=getFmtJu(aa[i],iMax);
return res+"</table>";
}
function onLoad(){
txtyun.value=help;
xmlpz=shiyun.XMLDocument.documentElement;
xmlpz.ownerDocument.setProperty("SelectionLanguage", "XPath")
}
function onTxtOver(){
if(txtyun.value == help)
txtyun.value="";
}
function findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
</script>
</head>
<body onload="return onLoad();" bgcolor="#F8F9FD" bottomMargin=0 leftMargin=0 topMargin=0 rightMargin=0>
<center>
<table ><tr>
<td >
<B><FONT style="FONT-SIZE: 25pt;FONT-FAMILY: 隶书">拼音查询</font></td></tr></table>
<table bgcolor=#E7E9EE cellspacing=0 border=0 >
<tr>
<td style="border-style: ridge; border-width: 1px" nowrap valign="top">
<textarea class=ai name=txtyun id=txtyun onfocus="return onTxtOver()" onclick="return onTxtOver()" ></textarea></td>
</tr>
</table>
<table bgcolor=#E7E9EE cellspacing=0 border=0 style="border-style: ridge; border-width: 1px"><tr>
<td >
<input type="button" value="清 空" onclick="txtyun.value=''" style="background-color: #E7E9EE;border-style: outset; border-width: 1px">
<input type="button" id=chkAll value="查 询" onclick="javascript:dsppz.innerHTML=getFmtShiCi(txtyun.value);" style="background-color: #E7E9EE;border-style: outset; border-width: 1px">
</td>
</tr></table>
<table bgcolor=#E7E9EE cellspacing=0 border=0 width=600 style="border-style: ridge; border-width: 1px">
<tr height=0>
<td id=dsppz>
</td>
</tr>
</table>
</center>
<xml id="shiyun" type="汉语拼音">
<zhonghuaxinyun>
<shisiyun type="阴平">
<yun type="ā">阿啊呵腌吖锕</yun>
<yun type="āi">哀挨埃唉哎捱锿</yun>
<yun type="ān">安谙鞍氨庵桉鹌广厂</yun>
<yun type="ānɡ">肮</yun>
<yun type="āo">熬凹</yun>
</shisiyun>
</zhonghuaxinyun>
</xml>
</body>
</html>
点击以下便可查看完整代码:
https://code.csdn.net/snippets/1643330/master/py.html/raw
2 个解决方案
#1
貌似是各浏览器之间js不兼容导致的,用jQuery重写js部分代码试试吧
#2
这一段代码我转为电子书都是可以正常使用的,因为是多年前的,重新不知从何下手,所以想让人看看有没有哪个地方出错。或者有人可以测试一下。
#1
貌似是各浏览器之间js不兼容导致的,用jQuery重写js部分代码试试吧
#2
这一段代码我转为电子书都是可以正常使用的,因为是多年前的,重新不知从何下手,所以想让人看看有没有哪个地方出错。或者有人可以测试一下。