試試這個http://jsfiddle.net/KgAe4/4/:
<div class="simpleCart_shelfItem">
<img src="image/frod001.gif" alt="" />
<p class="item_name">Fishing rod model 001</p>
<span class="item_price">BND $189.95</span><br/>
Qty: <input type="text" class="item_quantity" value="1" style="width:20px;"/><br/>
<input type="button" onclick="javascript:calculateText();" id="calculateText" value="add to cart" />
</div>
jQuery
$("#calculateText").on("click", function(){
var price = $(".item_price").text();
var priceSplit = price.split("$");
var realprice = parseFloat(priceSplit[1]);
alert(realprice);
var quantity = $(".item_quantity").val();
alert(realprice*quantity);
});
的Javascript
function calculateText(){
var price = document.getElementsByClassName("item_price")[0].innerHTML;
var priceSplit = price.split("$");
var realprice = parseFloat(priceSplit[1]);
var quantity = document.getElementsByClassName("item_quantity")[0].value;
alert(realprice*quantity);
}
你到底要什麼樣的按鈕點擊? 你能否指定你的要求? –
你用jQuery好嗎?這比純粹的JavaScript學習起來要容易得多,而且打字也少得多... – gibberish
到目前爲止,你有什麼嘗試?你的JavaScript在哪裏,你遇到了什麼錯誤/問題? – scrappedcola