Javascript 如何通过在NW.JS中单击按钮触发文件对话?
我想使用“图像作为”按钮在NW.JS中打开一个文件对话框,我该怎么做Javascript 如何通过在NW.JS中单击按钮触发文件对话?,javascript,node-webkit,nw.js,Javascript,Node Webkit,Nw.js,我想使用“图像作为”按钮在NW.JS中打开一个文件对话框,我该怎么做 <script> openbtn.addEventListener('click', e => opendlg.click()); opendlg.addEventListener('change', e => { let files = e.target.value; if (files) { e.target.value = ''; // or you will n
<script>
openbtn.addEventListener('click', e => opendlg.click());
opendlg.addEventListener('change', e => {
let files = e.target.value;
if (files) {
e.target.value = ''; // or you will not receive change-event next time on the same files
files.split(';').forEach(filepath => {
alert(filepath);
});
}
});
</script>
我有这个
HTML
<button id="open" style="background: none;"><img src="images/open.png" style="width:20px;background:none;"></button></div>
<input style="display:none;" id="fileDialog" type="file" />
<script>
openbtn.addEventListener('click', e => opendlg.click());
opendlg.addEventListener('change', e => {
let files = e.target.value;
if (files) {
e.target.value = ''; // or you will not receive change-event next time on the same files
files.split(';').forEach(filepath => {
alert(filepath);
});
}
});
</script>
以下是完整的工作示例:
<script>
openbtn.addEventListener('click', e => opendlg.click());
opendlg.addEventListener('change', e => {
let files = e.target.value;
if (files) {
e.target.value = ''; // or you will not receive change-event next time on the same files
files.split(';').forEach(filepath => {
alert(filepath);
});
}
});
</script>
openbtn.addEventListener('click',e=>opendlg.click());
opendlg.addEventListener('change',e=>{
让文件=e.target.value;
如果(文件){
e、 target.value='';//否则下次将不会收到相同文件上的更改事件
files.split(“;”).forEach(文件路径=>{
警报(文件路径);
});
}
});
以下是完整的工作示例:
<script>
openbtn.addEventListener('click', e => opendlg.click());
opendlg.addEventListener('change', e => {
let files = e.target.value;
if (files) {
e.target.value = ''; // or you will not receive change-event next time on the same files
files.split(';').forEach(filepath => {
alert(filepath);
});
}
});
</script>
openbtn.addEventListener('click',e=>opendlg.click());
opendlg.addEventListener('change',e=>{
让文件=e.target.value;
如果(文件){
e、 target.value='';//否则下次将不会收到相同文件上的更改事件
files.split(“;”).forEach(文件路径=>{
警报(文件路径);
});
}
});
您可以使用“自定义文件输入”方法:这可能有用:。这类似于文件对话框的nw api。您可以使用“自定义文件输入”方法:这可能有用:。这就像文件对话框的NWAPI。