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

其实很简单,

<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="保存" οnclick="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>  

  

转载于:https://www.cnblogs.com/JamyWong/p/7607964.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值