$(文件).height()没有问题

时间:2011-01-12 19:16:04

标签: jquery dom

为什么没有填充第3和第4个输入?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
label {
    display:block;
}
</style>
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
</head>

<body>
<form>
    <label for="WindowHeight">Window Height:</label>
    <input name="WindowHeight">
    <label for="WindowWidth">Window Width:</label>
    <input name="WindowWidth">
    <label for="DocumentHeight">Document Height:</label>
    <input name="DocumentHeight">
    <label for="DocumentWidth">Document Width:</label>
    <input name="DocumentWidth">
</form>
<script>
function Populate() {
    $('input[name=WindowHeight]').val($(window).height());
    $('input[name=WindowWidth]').val($(window).width());
    $('input[name=DocumentHeight').val($(document).height());
    $('input[name=DocumentWidth').val($(document).width());
}

$(window).resize(function() {
    Populate();
});
Populate();
</script>
</body>
</html>

2 个答案:

答案 0 :(得分:6)

你错过了两个]

function Populate() {
    $('input[name=WindowHeight]').val($(window).height());
    $('input[name=WindowWidth]').val($(window).width());
    $('input[name=DocumentHeight]').val($(document).height());
    //                        --^
    $('input[name=DocumentWidth]').val($(document).width());
    //                       --^
}

答案 1 :(得分:3)

您在这里缺少右括号:

$('input[name=DocumentHeight').val($(document).height());
$('input[name=DocumentWidth').val($(document).width());