Javascript none是您想要的。正如@Louisbatailard正确地提到的:不仅原始事件处理程序需要由用户启动;它必须是特定的单击事件。他提供了一把小提琴来演示这一点:你可以点击动态生成的东西。在jquery中,这是$(staticElementParent)。在

Javascript none是您想要的。正如@Louisbatailard正确地提到的:不仅原始事件处理程序需要由用户启动;它必须是特定的单击事件。他提供了一把小提琴来演示这一点:你可以点击动态生成的东西。在jquery中,这是$(staticElementParent)。在,javascript,jquery,html,Javascript,Jquery,Html,none是您想要的。正如@Louisbatailard正确地提到的:不仅原始事件处理程序需要由用户启动;它必须是特定的单击事件。他提供了一把小提琴来演示这一点:你可以点击动态生成的东西。在jquery中,这是$(staticElementParent)。在(“单击”,“dynamicChild”,function(){})谢谢!!!!我一直在javascript控制台中测试所有这些答案,我快发疯了!我已经花了半个小时的时间用编程方式提示一个文件输入窗口。没有其他人说如果事件不是由用户启动的,这是


none是您想要的。正如@Louisbatailard正确地提到的:不仅原始事件处理程序需要由用户启动;它必须是特定的单击事件。他提供了一把小提琴来演示这一点:你可以点击动态生成的东西。在jquery中,这是
$(staticElementParent)。在(“单击”,“dynamicChild”,function(){})
谢谢!!!!我一直在javascript控制台中测试所有这些答案,我快发疯了!我已经花了半个小时的时间用编程方式提示一个文件输入窗口。没有其他人说如果事件不是由用户启动的,这是不可能的。。。你应该得到很多+1。从
调试器开始
keyword不再中断编程点击我喜欢这个,不想在我的Angular项目中包含完整的jQuery,工作很好:)这种行为在所有现代浏览器中都可靠吗?这在没有任何JS的情况下工作,使用本机浏览器行为。与onDrop事件配合使用,实现功能丰富的文件上传效果非常好!我不得不摆弄CSS,但它成功了——也就是说,在所有浏览器中,具有“display:none”的文件输入可见性是不正常的。(但是可以使用不透明度0等)只需设置
即可消除应用CSS样式的需要。
$('input[type="file"]').click();
<input id="myInput" type="file" style="visibility:hidden" />
<input type="button" value="Show Dialog" onclick="$('#myInput').click();" />
<div class="btn" id="s_photo">Upload</div>

<input type="file" name="s_file" id="s_file" style="opacity: 0;">';

<!--jquery-->

<script>
    $("#s_photo").click(function() {
        $("#s_file").trigger("click");
    });
</script>
$('#fileInput').val('');
fileDialog()
    .then(file => {
        const data = new FormData()
        data.append('file', file[0])
        data.append('imageName', 'flower')

        // Post to server
        fetch('/uploadImage', {
            method: 'POST',
            body: data
        })
    })
<label class="btn btn-default fileLabel" data-toggle="tooltip" data-placement="top" title="Upload">
    <input type="file">
    <span><i class="fa fa-upload"></i></span>
</label>

<style>
    .fileLabel input[type="file"] {
        position: fixed;
        top: -1000px;
    }
</style>
openFileInput = () => {
    this.fileInput.click()
}
<a href="#" onClick={this.openFileInput}>
    <p>Carregue sua foto de perfil</p>
    <img src={img} />
</a>
<input style={{display:'none'}} ref={(input) => { this.fileInput = input; }} type="file"/>
class FileUploader extends Component {
  constructor (props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }
   onChange=(e,props)=>{
    const files = e.target.files;
    const selectedFile = files[0];
    ProcessFileUpload(selectedFile,props.ProgressCallBack,props.ErrorCallBack,props.CompleatedCallBack,props.BaseURL,props.Location,props.FilesAllowed);
  }
   handleClick = () => {
    this.refs.fileUploader.click();
  }
  render()
  {
  return(
      <div>
        <button type="button" onClick={this.handleClick}>Select File</button>  
        <input type='file' onChange={(e)=>this.onChange(e,this.props)} ref="fileUploader" style={{display:"none"}} />
      </div>)
  }
}
<div id="uploadButton">UPLOAD</div>
<form action="[FILE_HANDLER_URL]" style="display:none">
     <input id="myInput" type="file" />
</form>
<script>
  const uploadButton = document.getElementById('uploadButton');
  const myInput = document.getElementById('myInput');

  uploadButton.addEventListener('click', () => {
    myInput.click();
  });
</script>
let fileHandle;
async function fileOpen() {
    [fileHandle] = await window.showOpenFilePicker();
    const file = await fileHandle.getFile();
    console.log(await file.text());
}
// The advantage of this is fileHandle can be used to save to
// the opened file itself later, read more on this in https://web.dev/file-system-access/


// in April 2021, window.showOpenFilePicker still not support in Safari
// so one should have this around also
function legacyFileOpen() {
    var input = document.createElement('input');
    input.type = 'file';
    input.onchange = function () {
        input.files[0].arrayBuffer().then(function (arrayBuffer) {
            console.log(new TextDecoder().decode(arrayBuffer));
        });
    }
    input.click();
}