如何获取文件上传按钮的文本? [英] How can I get a file upload button's text?

查看:96
本文介绍了如何获取文件上传按钮的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为网络平台编写文档,我想在我的说明中引用文件上传按钮。但是,按钮上的确切文本取决于浏览器。例如,Firefox称之为浏览... ,Chrome称之为选择文件

I'm writing documentation for a web platform and I want to refer to a file upload button in my instructions. However, the exact text on the button depends on the browser. For example, Firefox calls it Browse... and Chrome calls it Choose File.

<input type="file">

是否可以通过编程方式访问(不更改)该文本?我知道我可以检测浏览器并相应地设置文档中的文本,甚至使用解决方法来设置按钮文本,但这不是我要问的。

Is it possible to access (not change) that text programmatically? I know I can detect the browser and set the text in the documentation accordingly, or even use a workaround to set the button text, but that's not what I'm asking.

推荐答案

此文本由浏览器呈现特定HTML元素的方式设置。无法访问或更改该文本。它永远不会加载到DOM中,因此通过jQuery查找也不是一个选项。

This text is set by how the browser renders that specific HTML element. There's no way to access or change that text. It will never be loaded into the DOM, so finding via jQuery is also not an option.

对于您的文档,您可能想要解决文本的IE版本将是,然后列出Chrome,Safari,Firefox等。这是我能想到的向用户解释的最佳方式。

For your documentation, you may want to address what the IE version of the text will be, then list Chrome, Safari, Firefox, etc. It's the best way I can think of to explain to the user.

编辑

我想我会更新并提及Shadow DOM,因为它对我来说很有意思。您可以在Chrome开发工具 - >设置 - >显示用户代理阴影DOM中启用此功能。在那里你可以实际查看渲染的控件和设置它的文本。虽然,它无法通过客户端脚本编程方式访问。 :(

Just thought I'd update and mention Shadow DOM because it's interesting and new to me. You can enable this in Chrome Dev Tools -> settings -> Show user agent shadow DOM. There you can actually view the rendered control and the text set to it. Although, it's not accessible programmatically through client side scripting. :(

这篇关于如何获取文件上传按钮的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆