【问题标题】:Calling .click() in a file input field brings up file browser but doesn't fill in path在文件输入字段中调用 .click() 会打开文件浏览器,但不会填写路径
【发布时间】:2011-11-04 06:37:46
【问题描述】:

单击图片按钮时,我激活了以下 jquery 调用:

$("#photo_input").click();

在 IE9 中,它会打开文件浏览器。但是,当我选择一个文件时,它不会更改路径。因此,我的 onchange 函数永远不会调用,也不会提交表单。这是输入字段的 html:

<input style = 'display:block' type = 'file' name = 'newPicture' id = 'photo_input' onchange = 'manual_photo_upload()'/>

它调用的函数只有一行:

$("#manual_photo_form").submit();

基本上,我想要的只是让用户点击图片按钮来上传文件。无论我将输入字段上的显示设置为阻止还是不显示,都是一样的。有什么办法可以解决这个问题?

【问题讨论】:

  • 我认为 Style = 在您的输入标签中产生了问题。只需将其删除,然后尝试。
  • 这实际上只是发帖的错误。我已经对其进行了编辑以反映我实际使用的内容。

标签: jquery html forms file-upload input


【解决方案1】:

尝试删除 onchange 属性并改用 jQuery 来处理事件:

$('#photo_input').change(function() {
    $("#manual_photo_form").submit();
});

【讨论】:

  • 删除 onchange 并使用它使其填充路径,但它不提交表单。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 2015-11-12
  • 2015-04-08
  • 2020-12-31
  • 2023-04-03
  • 1970-01-01
相关资源
最近更新 更多