如何使用JS来叠加双选

时间:2017-03-14 17:50:24

标签: javascript html css

我试图制作一个带有下拉列表和3个单选按钮的表单。 我想要的是当我点击提交时,检查两个选项。 我认为使用Javascript IF可以实现这一点,但我对此并不确定。 有人可以帮助我吗?

HTML

<body>
<div class ="container glass">
<div class= "center">
<form class = "resize" onSubmit="return checkAnswer();">
<legend>Pais</legend>
<select class = "resize" name="answer" id="answer" placeholder="Pais" required>
<option value="Italia">Italia</option>
<option value="Argentina">Argentina</option>
<input type="radio" name="editList" id="always" value="always"/>
<label for="always">Acta de Nacimiento</label>
<input type="radio" name="editList" id="never" value="never"/>
<label for="never">Acta de Matrimonio</label>
<input type="radio" name="editList" id="change" value="costChange"/>
<label for="change">Acta de Muerte</label>
<input type="submit" class = "resize" value="SUBMIT" />        
</select>
</form>          
</div>


1 个答案:

答案 0 :(得分:0)

使用jQuery,你的函数可能看起来像这样

$('button[type="submit"]').click(function(){
    var selectValue = $('#answer').val();
    swtich(selectValue){
        case "Italia":
            //do something
            break;
        case "Argentina":
            //do something else
            break;
    }
});