简体   繁体   English

一个更简单且功能齐全的数字选择器?

[英]A simpler and self-contained number picker?

In searching for number picker javascript code for a PhoneGap app I'm making, I came across this: https://plugins.jquery.com/dpNumberPicker/ 在搜索我正在制作的PhoneGap应用程序的数字选择器javascript代码时,遇到了这个问题: https : //plugins.jquery.com/dpNumberPicker/

It does what I need very well but looks overly complicated. 它确实满足了我的需求,但看起来过于复杂。 I've searched out lots of code and this one does what I need the best. 我已经搜索了很多代码,而这正是我所需要的。 I'm wondering if there's a much simpler way to achieve a cross-platform (Android and iOS) mobile-ready (tappable) number picker? 我想知道是否有更简单的方法来实现跨平台(Android和iOS)的移动就绪(可插拔)数字选择器? I need something that lets me make a stylable button with a - sign, stylable box where the number appears, and a following stylable + sign, and both buttons can be styled independently or both share the same style code, as well as the + and - being stylable as well. 我需要一些东西让我制作一个带有-号的可样式化按钮,在其中出现数字的可样式化框以及后面的可样式化+号,并且这两个按钮都可以独立设置样式或共享相同的样式代码,以及+和-风格也不错。

In short, this: [-][ 0 ][+] 简而言之,这是:[-] [0] [+]

Is there anything simpler (as in far less lines of code) that does what the DP Number Picker does the way it does it? 有没有什么比DP Number Picker的工作方式更简单的(如更少的代码行)? This number picker is handsome code but it came out in 2014. I was hoping there was a neater and shorter way to achieve this. 这个数字选择器是很帅的代码,但它于2014年问世。我希望有一个更简洁,更短的方法来实现这一目标。

If there's an answer to this, is there a way to make the buttons only appear and the number box be stylable when you tap on the number input box, and then the buttons disappear and number box goes back to its default untapped style after a pre-defined number of seconds of not tapping? 如果对此有答案,可以用一种方法使在单击数字输入框时仅显示按钮,并且数字框可样式化,然后按钮消失,并且数字框在预按后返回其默认的未使用样式。定义的不敲击秒数?

Going from this: 0 To this: [-][ 0 ][+] And back again after you stop tapping: 5

Ok, to answer your questions (as you commented that you only wanted to know if there was any point in trying to code this yourself): 好的,回答您的问题(正如您评论的那样,您只想知道尝试自己编写代码是否有任何意义):

Is there anything simpler (as in far less lines of code) that does what the DP Number Picker does the way it does it? 有没有什么比DP Number Picker的工作方式更简单的(如更少的代码行)? This number picker is handsome code but it came out in 2014. I was hoping there was a neater and shorter way to achieve this. 这个数字选择器是很帅的代码,但它于2014年问世。我希望有一个更简洁,更短的方法来实现这一目标。

Unless you can use <input type="number"> , you could code a custom solution yourself. 除非可以使用<input type="number"> ,否则您可以自己编写自定义解决方案。 A custom coded solution is almost always likely to be shorter than a general solution made by others, since you only code the functionality you specifically need. 自定义编码解决方案几乎总是比其他人提供的通用解决方案更短,因为您只编码自己需要的功能。 What you are asking should not be too hard to code, and probably a good exercise when learning JavaScript. 您要问的内容不应太难编写代码,在学习JavaScript时可能是一个很好的练习。

If there's an answer to this, is there a way to make the buttons only appear and the number box be stylable when you tap on the number input box, and then the buttons disappear and number box goes back to its default untapped style after a pre-defined number of seconds of not tapping? 如果对此有答案,可以用一种方法使在单击数字输入框时仅显示按钮,并且数字框可样式化,然后按钮消失,并且数字框在预按后返回其默认的未使用样式。定义的不敲击秒数?

Yes, you can make appearence and styling change as a result of user interaction by using event listeners on the input box and the buttons. 是的,您可以通过在输入框和按钮上使用事件侦听器来更改外观和样式,作为用户交互的结果。 You could also make the appearance change back to default after a set time of inactivity by debouncing . 您还可以通过设置一段时间的反跳操作,将外观更改为默认设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM