,所以我有這行代碼在我的HTML用JavaScript檢索HTML數據
<td class="product-price">
<span class="amount" id="price">3915.00</span>
</td>
如何我在JavaScript作爲一個整數號「3915.00」?
<script>
function myFunction()
{
var priceStr = document.getElementById('price').value;
var priceInt = parseInt(price);
}
</script>
我可以這樣做嗎?還是有其他選擇嗎?
跨度不具有價值屬性。得到它的「textContent」並將其解析爲INT或FLOAT。 –