我选择了带有两个选项'first'和'second'的表单,当我更改select选项时,我会看到更改准时,但此代码不起作用:(
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Condition <span class="condition">---</span><br/>
Select value <span class="value">---</span>
<script type="text/javascript">
$("#test").change(function() {
var test = $('#test option:selected').text();
$('.value').text(test);
if test == "first" {
var condition = 1
} else if test == "second" {
var condition = 0
}
$('.condition').text(condition);
});
</script>
答案 0 :(得分:0)
if else语句
中存在语法错误试试这个
if (test == "first") {
var condition = 1
} else if (test == "second") {
var condition = 0
}