以下脚本假设在单击时从函数返回变量。然而,它让我回到0.是。检查正确的jquery在这里使用?
JS:
function getBedroomSizePrice()
{
var bedroomSizePrice=0;
var theForm = document.forms["msform"];
var selectedBoiler = theForm.elements["bedroom"];
for(var i = 0; i < selectedBoiler.length; i++)
{
//if the radio button is checked
if(selectedBoiler[i].checked)
{
bedroomSizePrice = bedroom_prices[selectedBoiler[i].value];
break;
}
}
return bedroomSizePrice;
}
HTML:
<fieldset>
<h2 class="fs-title">How Many Bedrooms Do You Have</h2>
<h3 class="fs-subtitle"></h3>
<label >Number of Bedrooms</label>
<br/>
<label class='next action-button'><input type="button" name="bedroom" value="Bed1" onclick="calculateTotal()" />1</label><br/>
<label class='next action-button'><input type="button" name="bedroom" value="Beds2" onclick="calculateTotal()" />2</label><br/>
<label class='next action-button'><input type="button" name="bedroom" value="Beds3" onclick="calculateTotal()" />3</label><br/>
<label class='next action-button'><input type="button" name="bedroom" value="Beds4" onclick="calculateTotal()" />4</label><br/>
<label class='next action-button'><input type="button" name="bedroom" value="Beds5" onclick="calculateTotal()" />5</label><br/>
<label class='next action-button'><input type="button" name="bedroom" value="Beds6" onclick="calculateTotal()" />6</label><br/>
</fieldset>
答案 0 :(得分:0)
你必须改变 类型=&#34;无线电&#34;而不是键入=&#34;按钮&#34;
<fieldset>
<h2 class="fs-title">How Many Bedrooms Do You Have</h2>
<h3 class="fs-subtitle"></h3>
<label >Number of Bedrooms</label>
<br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Bed1" onclick="calculateTotal()" />1</label><br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Beds2" onclick="calculateTotal()" />2</label><br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Beds3" onclick="calculateTotal()" />3</label><br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Beds4" onclick="calculateTotal()" />4</label><br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Beds5" onclick="calculateTotal()" />5</label><br/>
<label class='next action-button'><input type="radio" name="bedroom" value="Beds6" onclick="calculateTotal()" />6</label><br/>
</fieldset>