Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript onchange函数获取正在显示隐藏的div的高度_Javascript_Jquery - Fatal编程技术网

Javascript onchange函数获取正在显示隐藏的div的高度

Javascript onchange函数获取正在显示隐藏的div的高度,javascript,jquery,Javascript,Jquery,我有一个选择框。在更改selectbox中的值时,div将显示和隐藏 div first的内容较少,div two的内容太多。 如果我从selectbox中选择div first showing和div two hiding,反之亦然, 但我的要求是,如果我选择第一个,我得到的是第二个高度,如果我选择第二个,我得到的是第二个高度 $("#test").change(function() { var j = $("#divfirst").find("body").height();

我有一个选择框。在更改selectbox中的值时,div将显示和隐藏

div first的内容较少,div two的内容太多。 如果我从selectbox中选择div first showing和div two hiding,反之亦然, 但我的要求是,如果我选择第一个,我得到的是第二个高度,如果我选择第二个,我得到的是第二个高度

$("#test").change(function() {
    var j = $("#divfirst").find("body").height();
    var w = $("#divtwo").find("body").height();
    alert(j);
    alert(w);
});
HTML:

请试试这个:

$("#test").change(function() {
var j = $("#divfirst").css('height').replace('px','');
var w = $("#divtwo").css('height').replace('px','');
 alert(j);
alert(w);
})
或者您可以使用:

$("#test").change(function() {
var j = $("#divfirst").offset().height;
var w = $("#divtwo").offset().height;
 alert(j);
alert(w);
})

只需$1.5的身高;将为您提供div heightno但我得到的是上一个div的高度,但当前divno如果我选择divfirst,现在再次更改为divtwo,那么我得到的是firstdiv的高度,因为它当前在DOM上。您可以创建小提琴吗,
$("#test").change(function() {
var j = $("#divfirst").offset().height;
var w = $("#divtwo").offset().height;
 alert(j);
alert(w);
})