Javascript / jQuery根据Selected Down Down项隐藏字段

时间:2011-03-04 15:18:00

标签: javascript jquery

我有一些代码,我为OnChange事件创建了一个完美的代码。

<script type="text/javascript">
                    function UpdEventChanged(selectEl) {
                        var text = selectEl.options[selectEl.selectedIndex].text;
                        if (text == "Sickness" || text == "Holiday") {
                            $("input[id$=eventPostCode").hide();
                            $("#ContentPlaceHolder1_LBLUpdPCReq").hide();
                            $("#ContentPlaceHolder1_lblUpdPC").hide();
                        }

                        else {
                            $("input[id$=eventPostCode").show();
                            $("#ContentPlaceHolder1_LBLUpdPCReq").show();
                            $("#ContentPlaceHolder1_lblUpdPC").show();
                        }
                    }
</script>

我需要集成上面的代码,使其适用于Page Load事件。这是我的代码:

// update Dialog
    $('#updatedialog').dialog({
        autoOpen: false,
        width: 500,
        buttons: {
            "update": function() {
                //alert(currentUpdateEvent.title);

                var eventToUpdate = {
                    id: currentUpdateEvent.id,
                    //title: $("#eventName").val(),
                    title: $("#EventSalesPerson option:selected").text(),
                    description: $("#eventDesc").val(),
                    salesperson: $("#EventSalesPerson option:selected").text(),
                    eventPostCode: $("input[id$=eventPostCode]").val(),
                    eventname: $("#EventEventName option:selected").text()
                };

                 {
                    PageMethods.UpdateEvent(eventToUpdate, updateSuccess);
                    $(this).dialog("close");

                    currentUpdateEvent.title = $("#eventName").val();
                    currentUpdateEvent.description = $("#eventDesc").val();
                    currentUpdateEvent.salesperson = $("#EventSalesPerson option:selected").text();
                    currentUpdateEvent.eventname = $("#EventEventName option:selected").text();
                    currentUpdateEvent.eventPostCode = $("input[id$=eventPostCode]").val();

                    $('#calendar').fullCalendar('updateEvent', currentUpdateEvent);
                    location.reload(true);
                }

            },
            "delete": function() {

                if (confirm("do you really want to delete this event?")) {

                    PageMethods.deleteEvent($("#eventId").val(), deleteSuccess);
                    $(this).dialog("close");
                    $('#calendar').fullCalendar('removeEvents', $("#eventId").val());
                }

            }

        }
    });

如果#EventEventName选择了text = Holiday或Sickness,那么我需要隐藏以下项目:

"input[id$=eventPostCode"
"#ContentPlaceHolder1_LBLUpdPCReq"
"#ContentPlaceHolder1_lblUpdPC"

显然,如果没有选择它们,则应显示上述内容。

由于

1 个答案:

答案 0 :(得分:1)

看起来你需要这样的东西:

var EventEventNameText = $('#EventEventName').val();
if (EventEventNameText=='Holiday' || EventEventNameText=='Sickness') {
    $('#eventPostCode').hide();
    $('#ContentPlaceHolder1_LBLUpdPCReq').hide();
    $('#ContentPlaceHolder1_lblUpdPC').hide();
}

让我知道这对你有用。