现在的位置: 首页 > 综合 > 正文

jquery获取div宽度的实现思路与代码

2012年10月01日 ⁄ 综合 ⁄ 共 665字 ⁄ 字号 评论关闭

jquery 获取 DIV的width的语句
复制代码 代码如下:
$("#keleyi_com").width();
其中keleyi_com为DIV的id。

完整示例代码

复制代码 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery 获取 DIV的width(宽度) - 柯乐义</title>
<script type="text/javascript" src="http://www.keleyi.com/keleyi/pmedia/jquery-1.8.3.min.js"></script>
</head>
<body>
<div id="keleyi_com" style="width:800px;border:1px solid silver">本DIV的id为keleyi_com;<br />为欢迎访问脚本之家http://www.jb51.net</div>
<script type="text/javascript">
$(document).ready(
function () {
alert("id为keleyi_com的width为:"+$("#keleyi_com").width());
}
)
</script>
</body>
</html>

抱歉!评论已关闭.