1

我有一个 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>
4

4 回答 4

0

您面临的问题是,通常选择框不会触发更改事件,而它们是focused.

由于您使用的是 JQuery,因此解决方案是.click()结合使用.blur()以触发onchange事件。

我找到了这个小提琴,它展示了你想要做什么:

http://jsfiddle.net/acrashik/wLWMc/

于 2013-01-30T15:49:00.320 回答
0

尝试这样的事情:

 $('#yourSelectId').change(function() {
    var selectedVal = $('#yourSelectId option:selected').attr('value');
});

确保您的代码在准备好的函数内 - http://api.jquery.com/ready/ 或者它在创建选择的 HTML 之后

于 2013-01-30T15:17:43.417 回答
-1

你可以试试jquery bind() 方法吗?如果它不起作用,请尝试检查您的选择中的值...可能有 INTEGERS 尝试然后将您的条件更改为:

if ($(this).val() == 3) {

于 2013-01-30T15:29:58.780 回答
-1

尝试在您的代码中使用 live

 $("#SRIEquipmentDDL").on('change',function() {
            if ($(this).val() == "3") {
                $("#SRILift").show();
            } else {
                $("#SRILift").hide();
            }
        });
于 2013-01-30T15:55:55.863 回答