这个 JS 脚本给了我一个警告框:
jQuery.UI.version = 1.0.2 --- Box Width: undefined
如何选择#ressized
?
<head>
<title></title>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
<script src="jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
<style>
#resizable { width: 200px; height: 150px; padding: 5px; border: 1px solid red;}
</style>
<script>
$(function () {
var boxWidth = $('#resizable').attr('width');
alert("jQuery.UI.version = " + jQuery.ui.version + " --- Box Width: " + boxWidth);
});
</script>
</head>
<body>
<div id="resizable" class=">
<div id="title">
<h2>
The expanding box
</h2>
</div>
</div>
</body>
最佳答案
请注意,您没有 width
属性:
<div id="resizable" class=">
这肯定会崩溃并设置为未定义
,var boxWidth = $('#resizing').attr('width');
有两种方法获取元素的宽度,例如:
通过.width()
方式:
$('#resizable').width();
并通过.css()
方式:
$('#resizable').css('width');
关于jquery - 当宽度由 css 类设置时获取 div 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15945877/