我有一个onChange事件,但在更改时它没有被触发。我已经确认我正在正确调用字段。
$("#SRIEquipmentDDL").change(function() {
if ($(this).val() == "3") {
$("#SRILift").show();
} else {
$("#SRILift").hide();
}
});
<div id="SRIEquipment">
<div class="TextField">Equipment:</div>
<div class="InputField">
<select name="SRIEquipmentDDL" id="SRIEquipmentDDL" class="DropDownField">
<option value="0" <?php if ($_POST['SRIEquipmentDDL'] == "0") {echo "selected='selected'";} ?> >Select Chair Type</option>
<option value="1" <?php if ($_POST['SRIEquipmentDDL'] == "1") {echo "selected='selected'";} ?> >Manual Wheelchair</option>
<option value="2" <?php if ($_POST['SRIEquipmentDDL'] == "2") {echo "selected='selected'";} ?>>Power Wheelchair</option>
<option value="3" <?php if ($_POST['SRIEquipmentDDL'] == "3") {echo "selected='selected'";} ?>>Lift Chair</option>
<option value="4" <?php if ($_POST['SRIEquipmentDDL'] == "4") {echo "selected='selected'";} ?>>Scooter</option>
<option value="5" <?php if ($_POST['SRIEquipmentDDL'] == "5") {echo "selected='selected'";} ?>>Lifts</option>
<option value="6" <?php if ($_POST['SRIEquipmentDDL'] == "6") {echo "selected='selected'";} ?>>CPM</option>
<option value="8" <?php if ($_POST['SRIEquipmentDDL'] == "7") {echo "selected='selected'";} ?>>Walker</option>
<option value="9" <?php if ($_POST['SRIEquipmentDDL'] == "8") {echo "selected='selected'";} ?>>Other</option>
</select>
</div>
</div>
<div id="SRILift">
<div class="TextField">Lift Type:</div>
<div class="InputField">
<select name="SRILiftTypeDDL" id="SRILiftTypeDDL" class="DropDownField">
<option value="0" <?php if ($_POST['SRILiftTypeDDL'] == "0") {echo "selected='selected'";} ?> >Select Lift Type</option>
<option value="1" <?php if ($_POST['SRILiftTypeDDL'] == "1") {echo "selected='selected'";} ?> >Stair Lift</option>
<option value="2" <?php if ($_POST['SRILiftTypeDDL'] == "2") {echo "selected='selected'";} ?>>Porch Lift</option>
<option value="3" <?php if ($_POST['SRILiftTypeDDL'] == "3") {echo "selected='selected'";} ?>>Outside Vehicle Lift</option>
<option value="4" <?php if ($_POST['SRILiftTypeDDL'] == "4") {echo "selected='selected'";} ?>>Inside Vehicle Lift</option>
<option value="5" <?php if ($_POST['SRILiftTypeDDL'] == "5") {echo "selected='selected'";} ?>>Ceiling Lift</option>
<option value="6" <?php if ($_POST['SRILiftTypeDDL'] == "6") {echo "selected='selected'";} ?>>Other</option>
</select>
</div>
</div>
答案 0 :(得分:0)
尝试这样的事情:
$('#yourSelectId').change(function() {
var selectedVal = $('#yourSelectId option:selected').attr('value');
});
确保您的代码位于就绪函数内 - http://api.jquery.com/ready/ 或者它是在HTML之后创建选择
答案 1 :(得分:0)
您遇到的问题是,选择框通常不会触发更改事件focused
。
由于您使用的是JQuery,因此解决方案是将.click()
与.blur()
结合使用,以便触发onchange
事件。
我发现这个小提琴演示了你想要做的事情:
答案 2 :(得分:-1)
你能试试jquery bind()方法吗? 如果它不起作用,请尝试检查您的内部值 选择......可能有INTEGERS尝试然后 将你的状况改为:
if($(this).val()== 3){
答案 3 :(得分:-1)
尝试在代码中使用live
$("#SRIEquipmentDDL").on('change',function() {
if ($(this).val() == "3") {
$("#SRILift").show();
} else {
$("#SRILift").hide();
}
});