HTML 选择快捷键覆盖
我有一个下拉列表(HTML 选择元素),其中仅包含一堆美元金额。例如
$50,000
$100,000
$150,000
$200,000
等等。
其中的选项元素之一的示例是:
<option value="150000">$150,000</option>
我希望用户能够开始输入 1..5..0.. 并使其自动跳转低至 150,000 美元的项目 - 如果我的 insidehtml 中没有任何 $ 符号,那么这在大多数浏览器中都可以正常工作。但是因为我所有的内部 HTML 描述都以 $ 符号为前缀,所以键盘快捷键都是相同的,所以实际上毫无用处。
我假设原始 HTML 中没有简单的方法来指定应该从相应的 value 属性而不是内部 HTML 文本获取键盘快捷键?
那么实现这一点的最干净的 jquery 片段是什么?
I have dropdown list (HTML select element) which simply contains a heap of dollar amounts. E.g.
$50,000
$100,000
$150,000
$200,000
and so on..
An example of one of the option elements inside it would be:
<option value="150000">$150,000</option>
I want the user to be able to start typing in 1..5..0.. and get it to auto-jump down to the $150,000 item - this works fine natively in most browsers if I didn't have any $ symbol in my innerhtml. But because all of my innerhtml descriptions are prefixed with a $ sign, the keyboard shortcuts are all identical, so effectively useless.
I'm assuming there is no simple way in raw HTML to specify that the keyboard shortcuts should be obtained from the corresponding value attribute, rather than the innerhtml text?
So what would be the cleanest jquery snippet to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果可能的话,我只需将
$
放在下拉菜单前面。这将是最不痛苦的方法。如果这不是一个选项,您可以考虑使用包含每个
选项
的$
符号的background-image
:浏览器对此的支持非常多,但是非常脆弱 - 它可能只能在每个系列的最新版本中工作。它可能根本不适用于 IE,我没有方便的概述。而且,这种方式也不利于今后的国际化。
除此之外,我认为您必须求助于基于 JavaScript 的自定义下拉菜单。
If at all possible, I would simply put the
$
in front of the drop down menu. That would be the least painful way.If that is not an option, you could consider using a
background-image
containing a$
sign for eachoption
:browser support for that is very, very flaky, though - it would work probably only in the very newest version of each family. It may not work in IE at all, I don't have an overview handy. Also, this way is not good for future internationalization.
Other than that, I think you would have to resort to a JavaScript based custom drop-down.