回答
var number = +$("#rate").text();
// | \______get text of span as string
// |_________________unary plus converts to numeric
可以使用text()方法和parseInt()將其轉換爲數字讓你span
內的文本:
var rateVal = parseInt($("#rate").text(), 10);
你可以這樣做也是這個
var result = Number($("#rate").html());
但小心使用數字功能,請看看這個討論區別parseInt和Number。正如羅科所指出的那樣:
What is the difference between parseInt(string) and Number(string) in JavaScript?。
http://stackoverflow.com/questions/4564158/what-is-the-difference-between-parseintstring-and-numberstring-in-javascript –
@ RokoC.Buljan現在用parseInt編輯了答案。 –
你應該刪除你的答案,否則它是Felix的答案的副本,並且順便提一句,你缺少'radix'參數。 –
- 1. 獲取dojo的值NodeList內部元素
- 2. 獲取其他元素內的元素
- 3. 獲取元素值
- 4. 獲取元素值
- 5. 如何從XML中的元素獲取內部元素值linq
- 6. 獲取XML元素的值
- 7. QTP - 獲取元素的值
- 8. 獲取元素的值
- 9. 獲取數組元素的所有值
- 10. 獲取點擊像素內的元素?
- 11. 獲取內嵌在JavaScript框架內的iframe中的元素值?
- 12. 獲取SoapBody元素值
- 13. 獲取jQuery元素值
- 14. 用元素樹獲取值
- 15. watir,按值獲取元素
- 16. 從元素獲取CSS值
- 17. jquery獲取子元素值
- 18. LinqtoXML:獲取元素值
- 19. Javascript獲取元素值
- 20. 獲取多個元素值
- 21. 獲取嵌套元素值
- 22. 獲取JSON數組元素值
- 23. PHP Array數組並獲取元素值
- 24. 在html標籤中獲取元素的值a元素的值
- 25. XSL每個元素的屬性值獲取元素值
- 26. 獲取視口內的元素像素數
- 27. 獲取元素內的文字
- 28. 獲取iframe的內部元素
- 29. 獲取文本xml元素的內容
- 30. 獲取元素的內容寬度
ha got it!,so +與Number()相同; – Ben