码迷,mamicode.com
首页 > 编程语言 > 详细

关于javascript以及jquery如何打开文件

时间:2017-09-28 18:35:59      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:文件   mp3   put   class   打开文件   saveas   rip   dial   保存   

其实很简单,

<input type="file" id="file"  mce_style="display:none">  

 这个就是html,call出文件对话框的。设置了隐藏。

只需要用javascript,或是jquery,用click函数call出,id为file就可以了。

<html>  
<head>  
   <title> New Document </title>  
</head>  
<body>  
<input type="file" id="file" style="display:none" mce_style="display:none">  
<input type="button" value="click" onClick="ok()">  
</body>  
<script language="JavaScript"> 
function ok(){  
var s = document.getElementById("file");  
s.click();  
}  
</script>  
</html>  

  

<html>  
<head>  
   <title> New Document </title>  
</head>  
<body>  
   <input type="button" value="保存" onclick="document.execCommand(‘SaveAs‘)">  
</body>  
<script language="JavaScript"> 
      function SaveAs()  
   {  
    var fileSave = new ActiveXObject("MSComDlg.CommonDialog");  
    fileSave.Filter = "mp3";  
          fileSave.FilterIndex = 2;  
          // 必须设置MaxFileSize. 否则出错  
          fileSave.MaxFileSize = 128;  
          fileSave.ShowOpen();  
      }  
</script>  
</html>  

  

关于javascript以及jquery如何打开文件

标签:文件   mp3   put   class   打开文件   saveas   rip   dial   保存   

原文地址:http://www.cnblogs.com/JamyWong/p/7607964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!