JavaScript按钮不反应
我的网站上有一个按钮。它应该写入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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论