我正在使用 asp.net 中的母版頁,并在 chrome 瀏覽器檢查工具控制臺中收到以下錯誤。未捕獲的類型錯誤:無法在 HTMLInputElement.onclick 的 myFunction (StudentPassword.aspx:258) 處設置屬性“類型”為 null我想問題出在腳本標簽上。我應該把它放在哪里?在標簽內部還是在內容頁的底部還是在母版頁的底部?母版頁是: <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Student.master.cs" Inherits="Project_Placements.Student" %> <!DOCTYPE HTML> <HTML> <head runat="server"> </head> <body> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> <script type="text/javascript"> function myFunction() { var checkBox = document.getElementById("myCheck"); var pwd = document.getElementById("password"); if (checkBox.checked == true) { pwd.type = 'password'; } else { pwd.type = 'text'; } } } </script> </body> </html>內容頁代碼如下: <%@ Page Title="" Language="C#" MasterPageFile="~/Student.Master" AutoEventWireup="true" CodeBehind="StudentPassword.aspx.cs" Inherits="Project_Placements.WebForm7" %> <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <form id="form1" runat="server"> <asp:TextBox ID="password" runat="server" TextMode="Password" ></asp:TextBox> <label for="myCheck">Show Password :</label> <input type="checkbox" id="myCheck" onclick="myFunction()"> </form> </asp:Content>
未捕獲的類型錯誤:無法將屬性“類型”設置為 null
拉丁的傳說
2022-11-11 13:31:26