我对 JS 相当陌生,这就是我到目前为止所拥有的。如果我减去值中的文本,我可以添加它,但这是我想要传递的东西。
$("#test").click(function() {
var total = 0;
$.each($(".sv-select") ,function() {
total += parseInt($(this).val());
});
$("input[value='15']").val(total);
});
HTML:
<form method="post" id="wpus-cart-button-form" class="wpus-cart-button-form beaver-run-- -bachelor-gulch-7/15---7/16" action="" onsubmit="return ReadForm(this, true);"><input type="hidden" name="quantity" value="1" /><label class="lv-label size">ROOM OPTIONS:</label> <br />
<select class="sv-select variation1" name="variation1" onchange="ReadForm (this.form, false);">
<option value="399 standard double room">standard double room $399.00</option>
<option value="499 upgraded king suite">upgraded king suite $499.00</option>
</select>
<p><br/><label class="lv-label color">ADD GUEST:</label><br />
<select class="sv-select variation2" name="variation2" onchange="ReadForm (this.form, false);">
<option value="0 no guests">no guests</option>
<option value="75 +1">+1</option>
</select>
<input type="hidden" name="product" value="Beaver Run - Bachelor Gulch 7/15 - 7/16" /><input type="hidden" name="price" value="15" /><input type="hidden" name="product_tmp" value="Beaver Run - Bachelor Gulch 7/15 - 7/16" /><input type="hidden" name="cartLink" value="http://performancecarclub.org/portfolio/beaver-run-bachelor-gulch-715-716/" /><input type="hidden" name="addcart" value="1" /><input id="test" class="vsubmit submit" type="submit" value="Purchase Trip!" /></form>
这是jsfiddle:http: //jsfiddle.net/rYfMx/