0

我有一个基于复选框 id 确定价格值的函数。这工作正常,除了我需要将复选框更改为选择。我试图改变这一行:

if(peo14.checked==true)

对此:

if(peo14.select==Yes)

这不起作用...如何将其更改为是/否选择?

function peoPrice()
{
    var peoPrice=0;
    //Get a reference to the form id="quicksheet"
    var theForm = document.forms["quicksheet"];
    //Get a reference to the checkbox id
    var peo14 = theForm.elements["peo14"];  

    //If they checked the box set peoPrice to value
    if(peo14.checked==true)
    {
        peoPrice=199;
    }       
    //finally we return the peoPrice
    return peoPrice;
}
4

2 回答 2

0

您必须使用该.options属性并选择所选索引,然后获取该索引的值。

if (peo14.options[ peo14.selectedIndex ].value === 'Yes') {
    peoPrice = 199;
}
于 2013-09-10T17:05:30.247 回答
-1

选择框


<select id="peo14" name='peo14' >
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
function peoPrice()
{
    var peoPrice=0;
    var e = document.getElementById("peo14");
    var peo14val = e.options[e.selectedIndex].value;

    if(peo14val=="Yes")
    {
        peoPrice=199;
    }       
    //finally we return the peoPrice
    return peoPrice;
}


于 2013-09-10T17:05:24.223 回答