2014-01-25 85 views

回答

4
var number = +$("#rate").text(); 
//   |    \______get text of span as string 
//   |_________________unary plus converts to numeric 
+0

ha got it!,so +与Number()相同; – Ben

0

可以使用text()方法和parseInt()将其转换为数字让你span内的文本:

var rateVal = parseInt($("#rate").text(), 10); 
0

你可以这样做也是这个

var result = Number($("#rate").html()); 

但小心使用数字功能,请看看这个讨论区别parseInt和Number。正如罗科所指出的那样:

What is the difference between parseInt(string) and Number(string) in JavaScript?

+1

http://stackoverflow.com/questions/4564158/what-is-the-difference-between-parseintstring-and-numberstring-in-javascript –

+0

@ RokoC.Buljan现在用parseInt编辑了答案。 –

+0

你应该删除你的答案,否则它是Felix的答案的副本,并且顺便提一句,你缺少'radix'参数。 –