getElementById 似乎在表单中失败

getElementById seems to fail within forms

我在获取特定网页上的 getElementById 时一直遇到问题。因此,我将其缩减为以下最少的代码。在此代码中,显示了第一个 alert(),但没有显示第二个,我唯一能猜到为什么 getElementById() 失败了。有什么想法吗?

<!doctype html>
<html>
    <head>
        <script type="text/javascript">
            function Process(X) {
                alert("In Process at A");
                var y = Document.getElementById("YourName").value;
                alert("At B");
            }
        </script>

        <meta charset="utf-8">
        <title>Test</title>
    </head>

    <body>
        <div>
            <form onsubmit="Process(getElementById('YourName').value);return false;">
                <label for="name">Your name</label>
                <input type="text" maxlength="50" name="YourName" id="YourName">

                <input type="submit" value="Do it" />
            </form> 
        </div>
    </body>
</html>

Document.getElementById 失败,因为 getElementByIddocument 对象的 属性 而不是 Document 对象。 JS是case-sensitive.

getElementById('YourName') 失败,因为 getElementByIddocument 对象的 属性 而不是全局对象。