Javascript .签入不适用于按钮样式输入
假设以下脚本在单击函数时从函数返回变量。但是,它正在将我返回到0。是否检查了要在此处使用的正确jquery js:Javascript .签入不适用于按钮样式输入,javascript,jquery,html,Javascript,Jquery,Html,假设以下脚本在单击函数时从函数返回变量。但是,它正在将我返回到0。是否检查了要在此处使用的正确jquery js: 函数getBeddroomSizePrice() { var bedroomSizePrice=0; var theForm=document.forms[“msform”]; var selectedBoiler=form.elements[“卧室”]; 对于(变量i=0;i
函数getBeddroomSizePrice()
{
var bedroomSizePrice=0;
var theForm=document.forms[“msform”];
var selectedBoiler=form.elements[“卧室”];
对于(变量i=0;i
html:
你们有多少间卧室
房间数量
1
2
3
4
5
6
您必须更改
type=“radio”而不是type=“button”
你们有多少间卧室
房间数量
1
2
3
4
5
6
我在js中看到“msform”,但在html中看不到。你是否遗漏了一些html?我没有看到任何复选框…他正在使用bootstrapButtons!==选中复选框并删除最后一个问题。另外,calculateTotal()在哪里定义?
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;
}
<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>
<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>