gpt4 book ai didi

jquery - 当 jquery 元素不存在时保持空白?

转载 作者:行者123 更新时间:2023-11-28 06:10:28 24 4
gpt4 key购买 nike

我有一个 gage从服务器获取数据后显示。量具仅在收到数据后显示,但我想弄清楚当量具不存在时如何保持 html 中的空白?目前,当量具不存在时,我的页面会跳起来,一旦出现就会弹出。我真的希望它淡入我猜。非常感谢。

html

<div id="gauge" class="400x260px"></div>

查询

<script>
$(document).ready(function(){
$("#submitButtonId").on("click",function(e){
e.preventDefault();

//Post form
var formdata = $(this.form).serialize();
$.post('insert.php', formdata,
function(data){
//Reset Form
$('#myform')[0].reset();
fetchRowCount();
});

return false;
});
});
//Fetch data from server
function fetchRowCount() {
$.ajax({
url: 'server2.php',
dataType: "json",
success: function (data) {
$("#rows").html(data.rows);
$("#min").html(data.min);
$("#max").html(data.max);
$("#mean").html(data.total);

//Show gage once json is receved from server

var gage = new JustGage({
id: "gauge",
value: data.total,
min: 1,
max: 100,
title: "Sample Data"
});

}
});

}
</script>

最佳答案

使用 CSS:

#gauge {
height: 260px;
}

使用jquery:

$('#guage').css({'height': '260px'});

CSS 应该是首选。

编辑:如果元素不总是那个高度,你总是可以使用最小高度。

关于jquery - 当 jquery 元素不存在时保持空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36199501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com