Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
扩展 TextInput 类/组件以接受“值”属性作为数字。我知道有一个限制方法,它只允许指定的字符。我遇到的问题是使用文本输入来获取框中的值并将其应用于脚本中的数学方程。有任何想法吗?
您可以限制TextInputto 0-9.,然后通过将其转换为数字来在脚本中使用它的值。
TextInput
0-9.
Math.sqrt(Number(textInput.text));
除了 Amarghosh 的:
如果您允许否定,则需要限制如下内容:“0-9\-”。(是的,三重转义...)
此外,如果您需要专门的选项(如从 Hex 解析),还有 parseInt 和 parseFloat 方法。
只要确保检查 NaN: 的结果isNan(result)?。
isNan(result)?