2013-12-14 65 views
-1

正確我不知道從哪裏開始,當涉及到正則表達式,但我認爲這是正確的方式去與此... 我想與javascript分離html我正在回想一下html元素所以:正則表達式在JavaScript中分割一個html字符串?

$('.HomeFeaturedPrice').each(function(index, el) { 
var grabPrice = $(this).html(); 
var convertPrice = Number(grabPrice); 
console.log(convertPrice); 
}); 

convertPrice可以輸出到現在不同的選擇:

選項之一是:$50.00

方案(2):<span id="salesprice">$50.90</span> 我怎樣寫一個正則表達式拿起只有價格。 ... 剝離出所有的html和美元符號... Chris

+0

[RegEx match open tags not except XHTML self-contained tags]可能重複(http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – bmargulies

+0

好吧,如果不是正則表達式,那麼如何呢? – vimes1984

回答

1

您不需要RegEx來實現這個簡單的事情。您可以執行以下操作。

var salesPrice = $("#salesprice").text(); 

這將使salesPrice變量等於span元素之間的任何值。

+0

基督你的權利我完全忘了.text()!!!上帝已經遲到了! – vimes1984

相關問題