可以jquery只获得像php这样的数字使用(int)获取数字?

时间:2011-09-14 06:52:00

标签: php jquery integer int

有没有一种方法jquery只能通过使用(int)来获取php如何获取数字的数字?

如果我正在尝试获取包含字符串和数字的文本

<div class='selector'>(4)</div>

$('.selector').text().int();

有什么类似于它应该只获得数字4的东西吗?

感谢您的帮助!

2 个答案:

答案 0 :(得分:1)

parseInt()应该做到这一点。示例(来自链接页面):

parseInt('123.45')  // 123
parseInt('77')      // 77
parseInt('077',10)  // 77
parseInt('77',8)    // 63  (= 7 + 7*8)
parseInt('077')     // 63  (= 7 + 7*8)
parseInt('77',16)   // 119 (= 7 + 7*16)
parseInt('0x77')    // 119 (= 7 + 7*16)
parseInt('099')     // 0 (9 is not an octal digit)
parseInt('99',8)    // NaN (0 in very old browsers e.g. MSIE 3.0)
parseInt('0.1e6')   // 0
parseInt('ZZ',36)   // 1295 (= 35 + 35*36)

当然,您可以将变量放在parseInt()以及字符串中。

正如zerkms在评论中所说,你实际上并不需要 jQuery来做这件事。 JavaScript有比jQuery更多的功能; - )

答案 1 :(得分:0)

在javascript中有一个名为parseInt()的函数。