JavaScript按钮不反应

发布于 2025-02-08 14:51:12 字数 2798 浏览 0 评论 0原文

我的网站上有一个按钮。它应该写入Firebase数据库。但是,这是不重要的。看来可以使用我的代码找到按钮。我尝试添加警报(“ Hello World”),但它仍然不重要。 IDS也对应于GET元素。

代码

    <head>
    <script src="https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.8.1/firebase-database.js"></script>
    </head>
    <body>
</div>
                        <tr>
                            <td>
                                <button id="btnSubmit">Submit</button>
                            </td>
                           
                        </tr>
                    </table>
                </form>
    
            </div>
        </div>
  
    <script type = "module">
            const firebaseConfig = {
              apiKey: "***",
              authDomain: "***",
              databaseURL: "***",
              projectId: "***",
              storageBucket: "***",
              messagingSenderId: "***",
              appId: "***",
              measurementId: "***"
            };
          
            // Initialize Firebase
            const app = initializeApp(firebaseConfig);
            var firebaseRef=firebase.database().ref('quotes');
    
            
            document.getElementById("btnSubmit").addEventListener('click', function(){
                //PROBLEM SEEMS TO BE HERE
                alert("hello world");
                var id=Date.now();  //generating a unqiue id
                const companyName=document.getElementById('cname').value;
                const grade=document.getElementById('grade').value;
                const concrete=document.getElementById('concrete').value;
                const formWorks=document.getElementById('formworks').value;
                const wall=document.getElementById('wall').value;
                const excavation = document.querySelector('.excavation:checked').value;
                const typeWork=document.getElementById("typeWork")
                const paint = document.querySelector('.paint:checked').value;
                const comments=document.getElementById('comments').value;
                const total=document.getElementById('total').value;
                firebaseRef.child(id).push({
                   companyName:companyName,
                   grade:grade,
                   concrete:concrete,
                   formWorks:formWorks,
                   wall:wall,
                   excavation:excavation,
                   typeWork:typeWork,
                   paint:paint,
                   comments:comments,
                   total:total
                });
            });
        </script>
        
    </body>
    </html>

I have a button on my website. It is supposed to write to firebase database. However it is irresponsive. It appears that the button can be found using my code. I tried adding alert("hello world"), but it is still irresponsive. The ids corresponds to the get element as well.

Code

    <head>
    <script src="https://www.gstatic.com/firebasejs/9.8.3/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.8.1/firebase-database.js"></script>
    </head>
    <body>
</div>
                        <tr>
                            <td>
                                <button id="btnSubmit">Submit</button>
                            </td>
                           
                        </tr>
                    </table>
                </form>
    
            </div>
        </div>
  
    <script type = "module">
            const firebaseConfig = {
              apiKey: "***",
              authDomain: "***",
              databaseURL: "***",
              projectId: "***",
              storageBucket: "***",
              messagingSenderId: "***",
              appId: "***",
              measurementId: "***"
            };
          
            // Initialize Firebase
            const app = initializeApp(firebaseConfig);
            var firebaseRef=firebase.database().ref('quotes');
    
            
            document.getElementById("btnSubmit").addEventListener('click', function(){
                //PROBLEM SEEMS TO BE HERE
                alert("hello world");
                var id=Date.now();  //generating a unqiue id
                const companyName=document.getElementById('cname').value;
                const grade=document.getElementById('grade').value;
                const concrete=document.getElementById('concrete').value;
                const formWorks=document.getElementById('formworks').value;
                const wall=document.getElementById('wall').value;
                const excavation = document.querySelector('.excavation:checked').value;
                const typeWork=document.getElementById("typeWork")
                const paint = document.querySelector('.paint:checked').value;
                const comments=document.getElementById('comments').value;
                const total=document.getElementById('total').value;
                firebaseRef.child(id).push({
                   companyName:companyName,
                   grade:grade,
                   concrete:concrete,
                   formWorks:formWorks,
                   wall:wall,
                   excavation:excavation,
                   typeWork:typeWork,
                   paint:paint,
                   comments:comments,
                   total:total
                });
            });
        </script>
        
    </body>
    </html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文