在同一页面内实现点击下拉菜单并显示选中文件的内容 在线等 文本类型的或者说是.jsp类型的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我查了下,网上大概提到3种方法 方法一: 做一个 <iframe src="aaa.txt" style="display:none" name="textfilewin"></iframe> js 再读取 iframe 中的内容. 方法二: 不用 frame/iframe 的话,可以用 xmlHTTP 的GET方法,读到文件的内容. 方法三: 用FSO 直白的说就是我要从下拉菜单中选中一个文件,比如file1我想在同一页面的文本框中显示文件file1的内容file1就是几个简单的数字而已就是这样的 有没有具体的代码方法二和三有点难以掌握用iframe应该更容易一些不过这样的话,不是要建一个子窗口,那就不在一个页面上了,要做跳转了 第一个不需要重新建页面,直接在页面就可以使用IFRAME;第二个:<SCRIPT LANGUAGE="JavaScript"><!--xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")xmlhttp.open("POST","http://bbs.51js.com/faq.php",true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){alert(xmlhttp.responseText.split("\n")[1]);}}xmlhttp.send("");//--></SCRIPT>第三个:<SCRIPT LANGUAGE="JavaScript"><!--var ForReading=1;var fso=new ActiveXObject("Scripting.FileSystemObject");var f=fso.OpenTextFile("C:\\r.txt",ForReading,true);if(f.AtEndOfLine){ alert('空文件!');}else{ alert(f.ReadAll());}f.Close();//--></SCRIPT> 要的是下面这种效果???test.htm<html><head> <title>Test</title> <script type="text/javascript"> function ShowMenu() { Menu.style.top=parseInt(Div1.offsetTop)+parseInt(Div1.style.height); Menu.style.left=parseInt(Div1.offsetLeft); Menu.style.display=""; } function HideMenu(e) { Menu.style.display="none"; } function ShowFile(url) { var myframe=document.getElementById('myframe'); myframe.style.display="block"; myframe.src=url; } </script></head><body><div id="Div1" style="background-color:#AAAAAA;width:100px;height:20px" onmouseover="ShowMenu()" onmouseout="HideMenu('D')">菜单测试</div><br /><div id="Menu" style="display:none;position:absolute;background-color:#999999;width:100px;z-index:1" onmouseover="ShowMenu()" onmouseout="HideMenu()"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td onclick="ShowFile('file1.htm')">file1</td></tr><tr><td onclick="ShowFile('file2.txt')">file2</td></tr><tr><td onclick="ShowFile('file2.htm')">file3</td></tr></table></div><iframe style='display:none' id='myframe'></iframe></body></html>加粗的为文件中的内容file1.htmfile1.htmfile2.txtfile2.txtfile2.htmfile2.htm Extjs4.1 设置了waitMsg后 这个下拉效果一直很困惑.求解 关于js的settimeout的问题急 这个用 onchange怎么实现 最好能帮写一下 在没提交表单的情况下 如何动态获取表单的值呢? 这个是什么格式的字符串啊?如何解密呢? javascript怎么给文件表单设值 一个框架问题,答对者200分相赠 我想通过点击SELECT里的内容之后打开一个新窗口,应该怎么写?里面有代码,怎么修改? 想知道这段代码的都是什么意思?请帮忙解答,谢谢各位了 高手来,寻高效表格排序算法 帮忙解释下:scrollTop、offsetTop?
方法一:
做一个 <iframe src="aaa.txt" style="display:none" name="textfilewin"></iframe>
js 再读取 iframe 中的内容.
方法二:
不用 frame/iframe 的话,可以用 xmlHTTP 的GET方法,读到文件的内容.
方法三:
用FSO
我想在同一页面的文本框中显示文件file1的内容
file1就是几个简单的数字而已
就是这样的
方法二和三有点难以掌握
用iframe应该更容易一些
不过这样的话,不是要建一个子窗口,那就不在一个页面上了,要做跳转了
第二个:
<SCRIPT LANGUAGE="JavaScript">
<!--
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
xmlhttp.open("POST","http://bbs.51js.com/faq.php",true);xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4)
{
alert(xmlhttp.responseText.split("\n")[1]);
}
}
xmlhttp.send("");
//-->
</SCRIPT>
第三个:
<SCRIPT LANGUAGE="JavaScript">
<!--
var ForReading=1;
var fso=new ActiveXObject("Scripting.FileSystemObject");
var f=fso.OpenTextFile("C:\\r.txt",ForReading,true);
if(f.AtEndOfLine){
alert('空文件!');
}
else{
alert(f.ReadAll());
}
f.Close();
//-->
</SCRIPT>
test.htm<html>
<head>
<title>Test</title>
<script type="text/javascript">
function ShowMenu()
{
Menu.style.top=parseInt(Div1.offsetTop)+parseInt(Div1.style.height);
Menu.style.left=parseInt(Div1.offsetLeft);
Menu.style.display="";
}
function HideMenu(e)
{
Menu.style.display="none";
}
function ShowFile(url)
{
var myframe=document.getElementById('myframe');
myframe.style.display="block";
myframe.src=url;
}
</script>
</head>
<body>
<div id="Div1" style="background-color:#AAAAAA;width:100px;height:20px" onmouseover="ShowMenu()" onmouseout="HideMenu('D')">菜单测试</div>
<br />
<div id="Menu" style="display:none;position:absolute;background-color:#999999;width:100px;z-index:1" onmouseover="ShowMenu()" onmouseout="HideMenu()">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr><td onclick="ShowFile('file1.htm')">file1</td></tr>
<tr><td onclick="ShowFile('file2.txt')">file2</td></tr>
<tr><td onclick="ShowFile('file2.htm')">file3</td></tr>
</table>
</div>
<iframe style='display:none' id='myframe'></iframe>
</body>
</html>加粗的为文件中的内容
file1.htm
file1.htmfile2.txt
file2.txtfile2.htm
file2.htm