javascript - 将工具提示添加到文件浏览输入

标签 javascript html google-chrome microsoft-edge

给定以下代码,自定义按钮鼠标悬停工具提示的最佳方法是什么?在 Chrome 中,工具提示自动设置为“未选择文件”。在 Edge 中没有默认的工具提示。 JavaScript 是必需的吗?

<div id="Dialog--Person">
  <form>
    <input placeholder="Enter First Name..." id="personFirstName" >
    <input placeholder="Enter Last Name..." id="personLastName" >
    <input placeholder="Enter Title..." id="personTitle" >
    <input placeholder="Enter Office Phone..." id="personPhone" >
    <input placeholder="Enter Mobile Phone..." id="personMobile" >
    <input placeholder="Enter Email..." id="personEmail" >
    <input type="file" value="upload" class="form-control" id="personPhoto" name="photo">
  </form>
</div>

Codepen

最佳答案

您需要添加 title 并传递您想要显示的任何值,如下面的概念。它将适用于所有浏览器并在工具提示中显示相同的文本。

<input type="file" value="upload" class="form-control" id="personPhoto" name="photo" title="Please select file."> 

<div id="Dialog--Person">
  <form>
    <input placeholder="Enter First Name..." id="personFirstName" >
    <input placeholder="Enter Last Name..." id="personLastName" >
    <input placeholder="Enter Title..." id="personTitle" >
    <input placeholder="Enter Office Phone..." id="personPhone" >
    <input placeholder="Enter Mobile Phone..." id="personMobile" >
    <input placeholder="Enter Email..." id="personEmail" >
    <input type="file" value="upload" class="form-control" id="personPhoto" name="photo" title="Please select file.">
  </form>
</div>

关于javascript - 将工具提示添加到文件浏览输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49490595/

相关文章:

javascript - 代码在 jsfiddle 中有效,但在 chrome 中无效。 - 未捕获的类型错误 : Cannot read property 'style' of undefined

javascript - 检查输入时切换标签类 javascript

javascript - 在 div 标签内添加一个 div 以在悬停时显示

javascript - Select2 AJAX 不起作用

javascript - 使用 gatsby-drupal-webform 和 GraphQL 时出现错误未知类型 "webform__webform"

javascript - PHP-Javascript 交互

html - 如何将此图像定位在页面的底部中心?

javascript - Chrome 调试器 - 如何关闭 console.log 消息分组?

javascript - window.open从Chrome到IE

javascript - 在 Chrome 扩展程序中从 popup.html 连接到 background.js 脚本