当javascript onchange中的值内部回显不起作用时。它必须再次点击/选择以显示div。选择选项值时显示/隐藏Div
<?php
$test = '1';
?>
<select name="request" id="reqtypev" class="form-control1" >
<option value="<?php echo $test ?>" selected="selected"><?php echo $test ?></option>
</select>
它确实工作,如果你没有使用PHP回显它。
//javascript
$('#reqtypev').change(function(){
if($(this).val()==="1" || $(this).val()==="2" || $(this).val()==="3" || $(this).val()==="4"){
$("#otherTypev").show()
} else {
$("#otherTypev").hide()
}
});
如何在使用php回显时执行javascript?
在选项值至少为2倍的值的功能活性()来行动。 –
对我来说,逻辑应该是'if(this.selectedIndex> 0)...'那么你可以有无限数量的选项,并且只有在选择了第一个选项以外的选项时才显示div(假设第一个('select ...'),或者甚至是$('#reqtypev')。change(function(){$('#otherTypev')[this.selectedIndex> 0?'show':'隐藏']()})'。 – RobG