我需要添加一个条件语句来将css高度链接到下拉选择(jQuery)

I need to add a conditional statement to link css height to pulldown selection (jQuery)

本文关键字:链接 高度 css jQuery 选择 语句 添加 条件 一个      更新时间:2023-09-26

我的代码中有这个,目前:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
$( "#grow" ).click(function(){
    $( "#background" ).animate( { height: "800" })
});
$( "#shrink" ).click(function(){
    $( "#background" ).animate({ height: "585" });
});

它增加或缩小背景容器,并将底部css保持在主窗体的正下方。然而,我需要在高度上添加一个下拉菜单,其中包含隐藏字段和相关的错误消息(或者,如果他们选择另一个下拉选项,则收缩它)。

我该怎么做有什么想法吗?我的下拉列表的ID是:ddlFeedbackType,有一个onChange事件处理程序,名为onChange="ShowHidePageURL()",下面是隐藏/显示脚本:

var x;
var o = document.getElementById ('plc_lt_zoneContent_pageplaceholder_pageplaceholder_lt_zoneCenter_ASME_FormsSuggestionForm_ddlFeedbackType');
if (o.options[o.selectedIndex].text == "Report a Bug") {
    x = document.getElementById('divPageURLlabel');
    x.style.display = "block";
    x = document.getElementById('divPageURLtext');
    x.style.display = "block";
    x = document.getElementById('divFeedbackType');
    x.style.display = "none";
    x = document.getElementById('lblFeedbackType');
    x.style.display = "none";
}

我只是不知道如何把这一切放在一起,任何帮助都将不胜感激。非常感谢。

假设以下HTML结构

<div id="#background">
   <form id="form">
      ....
   </form>
</div>

你应该把它设计成:

#background{height:585px;overflow:hidden;}

然后在您的javascript:中

$( "#grow" ).click(function(){
    if(test your pulldown value){
       $('<controls to hide>').hide();
    } else {
       $('<controls to show>').show();
    }
    $( "#background" ).animate( { height: $('form').height() })
});
$( "#shrink" ).click(function(){
    $( "#background" ).animate({ height: "585" });
});

这样,#背景将始终按照窗体的高度设置动画,因此如果控件被隐藏,则高度将适应。