开发者

Extending the TextInput class

Extend the TextInput Class/component to accept a "value" property as a number. I know there is a restrict method, that only allows for specified characters. The problem I am having 开发者_JS百科is using a textinput to take the value in the box and apply it to math equations in a script. Any ideas?


You can restrict the TextInput to 0-9. and then use its value in the script by casting it to a Number.

Math.sqrt(Number(textInput.text));


In addition to Amarghosh's:

You'll need to restrict something like this: "0-9\-" if you allow negatives. (yes triple-escaped...)

Also, there's the parseInt and parseFloat methods if you need specialized options like parsing from Hex.

Just make sure you check your result for NaN: isNan(result)?.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜