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

Phi*_*enn 2 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>
Run Code Online (Sandbox Code Playgroud)

Mic*_*ren 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());
    //                       --^
}
Run Code Online (Sandbox Code Playgroud)