文件夹选择:
<html> <head> <title>上传本地文件夹路径</title> <script type="text/javascript" language="javascript"> /* * 特别注意的是,由于安全方面的问题,你还需要如下设置才能使本JS代码正确运行, * 否者会出现"没有权限"的问题. * * 1、设置可信任站点(例如本地的可以为:http://localhost) * 2、其次:可信任站点安全级别自定义设置中:设置下面的选项 * "对没有标记为安全的ActiveX控件进行初始化和脚本运行"----"启用" */ function browseFolder(path) { try { var Message = "\u8bf7\u9009\u62e9\u6587\u4ef6\u5939"; //选择框提示信息 var Shell = new ActiveXObject("Shell.Application"); var Folder = Shell.BrowseForFolder(0, Message, 64, 0x11);//起始目录为:我的电脑 //var Folder = Shell.BrowseForFolder(0,Message,0); //起始目录为:桌面 if (Folder != null) { Folder = Folder.items(); // 返回 FolderItems 对象 Folder = Folder.item(); // 返回 Folderitem 对象 Folder = Folder.Path; // 返回路径 if (Folder.charAt(Folder.length - 1) != "\\") { Folder = Folder + "\\"; } document.getElementById(path).value = Folder; return Folder; } } catch (e) { alert(e.message); } } </script> </head> <body> <table> <tr> <td> <input type="text" name="path" /> </td> <td> <input type="button" onclick="browseFolder('path')" value="选择文件夹" /> </td> </tr> </table> </body> </html>
?判断滚动条是否到底(仅适用于火狐,IE会提示两次,不明原因):
<html > <head> <title>下拉滚动条滚到底部了吗?</title> <script language="javascript"> function scrollTo() { var scroller = document.getElementById("div1"); var nDivHight = scroller.style.height; var nScrollHight = scroller.scrollHeight;//滚动距离总长(注意不是滚动条的长度) var nScrollTop = scroller.scrollTop;//滚动到的当前位置 if (parseInt(nScrollTop) + parseInt(nDivHight) == nScrollHight) { alert("滚动条1到底部了"); } } function scrollTo2() { var scroller = document.getElementById("div2"); var nDivHight = scroller.style.height; var nScrollHight = scroller.scrollHeight;//滚动距离总长(注意不是滚动条的长度) var nScrollTop = scroller.scrollTop;//滚动到的当前位置 if (parseInt(nScrollTop) + parseInt(nDivHight) == nScrollHight) { alert("滚动条2到底部了"); } } </script> </head> <body> <div id="div1" style="overflow-y: auto; overflow-x: hidden; height: 500px;" onScroll="scrollTo()"> <div style="background-color: #ccc; height: 750px;"> 内部div高度为750,外部div高度为500,所以垂直滚动条需要滚动750-500=250的距离,就会到达底部 </div> </div> <br/> <div id="div2" style="overflow-y: auto; overflow-x: hidden; height: 200px;border: 1px;border: 1px dashed red" onScroll="scrollTo2()"> 滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/> 滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/>滚动<br/> </div> </body> </html>?