我正在尝试发送通过文本框接收到的用户输入,然后将该输入发送到 javascript,这是另一个文件(myfile.js)。由于某种原因,html 部分无法正常工作。这是代码:myfile.js:
var TRange=null;
function findString (str) {
if (parseInt(navigator.appVersion)<4) return;
var strFound;
if (window.find) {
// CODE FOR BROWSERS THAT SUPPORT window.find
strFound=self.find(str);
if (!strFound) {
strFound=self.find(str,0,1);
while (self.find(str,0,1)) continue;
}
}
else if (navigator.appName.indexOf("Microsoft")!=-1) {
// EXPLORER-SPECIFIC CODE
if (TRange!=null) {
TRange.collapse(false);
strFound=TRange.findText(str);
if (strFound) TRange.select();
}
if (TRange==null || strFound==0) {
TRange=self.document.body.createTextRange();
strFound=TRange.findText(str);
if (strFound) TRange.select();
}
}
else if (navigator.appName=="Opera") {
alert ("Opera browsers not supported, sorry...")
return;
}
if (!strFound) alert ("String '"+str+"' not found!")
return;
}
搜索.html
<!DOCTYPE html>
<HTML>
<HEAD>
</head>
<title>Search</title>
<body>
<script src="myfile.js" type="text/javascript"></script>
<form name="input">
Search for: <input type="text" id ="keytex" name="keytext" onClick='if(document.getElementById("keytex").value!=\'\') findString(document.getElementById("keytex").value); return(false);'>
</form>
<p> You can search this text. Search the text again</p>
</body>
</html>