我编写了以下代码,它返回undefined
if(('#listSearchOptions').scrollHeight !== ('#listSearchOptions').clientHeight){
$('#listSearchOptions').css({"height":"auto", "max-height":""});
console.log("Height..." + ('#listSearchOptions').clientHeight); //results undefined
}

这里有什么问题?
答案 0 :(得分:1)
您错过了$
并且使用了常规的JavaScript表达式:将.scrollHeight
替换为[0].scrollHeight
。并按.clientHeight
.height()
这很好用
if($('#listSearchOptions')[0].scrollHeight !== $('#listSearchOptions').height()){
$('#listSearchOptions').css({"height":"auto", "max-height":""});
console.log("Height..." + $('#listSearchOptions').height()); //results undefined
}