我正在尝试在 javascript 中检索 html 元素宽度。屏幕上什么也没有出现(纯文本有效,所以我想语法有问题)。我究竟做错了什么?谢谢
<head>
<script type="text/javascript">
var width = $("#menu").width();
document.write(width);
</script>
</head>
<body>
<h1> Example </h1>
<ul id = "menu">
<li><img src="img/Logo.jpg"/></li>
<li><a href ="#">Home</a>
<ul class = "sub1">
<li><a href ="#">News</a></li>
</ul>
</li>
<li><a href ="#">Machines</a>
<ul class = "sub1">
<li><a href ="#">Type1</a></li>
<li><a href ="#">Type2</a></li>
<li><a href ="#">Type3</a></li>
</ul>
</li>
<li><a href ="#">Mission</a></li>
<li><a href ="#">Contacts</a></li>
</ul>
<div id "main">
<h2> Whatever </h2>
</div>
</body>