【发布时间】:2011-09-21 12:21:49
【问题描述】:
我需要控制 div 的高度始终以 20 步长显示。我有一个重复的 div 背景,高 20 像素,我希望 div 始终以正确的方式结束。我在这里找到了我认为的解决方案: Set height of an element on multiples of a number?
但是当我尝试时它不起作用。我是 jquery 的新手,可能犯了一个简单的错误。
在下面的测试 html 代码中,我希望 div 的高度始终以 100 像素的步长出现,但它不起作用。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://`enter code here`www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test jquery</title>
<script type="text/javascript" src="jquery.js"></script>
<script language=”javascript”>
$(document).ready(function(){
$('#testCol').height(function(i, h) { return Math.ceil(h / 100) * 100; });
});
</script>
<style type="text/css">
#testCol {
width: 150px;
background-color:#FFCC00;
}
</style>
</head>
<body>
<div id="testCol">df ds d sfdhs fdsf ds fhsdu ds iuhsdi fsdf dhsf sdiuh isdf iusd fiushd fiuds i uhsdiu isudf iusd fiusdh fiusd fih wtwpr wer rew</div>
</body>
</html>
【问题讨论】: