【问题标题】:Assign first-of-type child's height to parent将第一个类型孩子的身高分配给父母
【发布时间】:2018-08-28 20:22:01
【问题描述】:

我有这个表格:

<form method="get" id="filterForK2ModuleForm">
    <input type="hidden" name="option">
    <input type="hidden" name="view">
    <input type="hidden" name="task">
    <input type="hidden" name="mid">
    <input type="hidden" name="Itemid">

    <div id="filter_field_33" class="field_checkbox" style="height: 50px;">
    </div>
    <div id="filter_field_4" class="field_radio" style="height: 50px;">
    </div>
    <div id="filter_field_11" class="field_radio" style="height: 50px;">
    </div>
    <div id="filter_field_22" class="field_checkbox" style="height: 50px;">
    </div>
</form>

并希望将第一个子 div(它具有可变 ID)的高度分配给它的父级。 (网站上有一个按钮可以将高度设置回100%)

但是当我尝试在变量中写入高度时:

<script type="text/javascript">
jQuery(document).ready( function() {
    var filterheight = $("#filterForK2ModuleForm div:first-of-type").height();
});
</script>

控制台显示Uncaught ReferenceError: func is not defined

你能帮我完成这个简单的任务吗?

【问题讨论】:

标签: jquery css height


【解决方案1】:

我无法用 jquery 做到这一点,但是这个 javascript 可以工作:

<script type="text/javascript">
    window.onload = function() {
            var filterheight = document.getElementById('filterForK2ModuleForm').getElementsByTagName('div')[0].clientHeight;
            document.getElementById("filterForK2ModuleForm").style.height = (filterheight + 'px');
    }
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多