简体   繁体   English

我正在尝试删除 btn 但它不起作用

[英]I am trying to make delete btn but its not working

I am trying to make a delete button for my calculator project.我正在尝试为我的计算器项目制作一个删除按钮。 But, its not working well.但是,它的工作并不好。

 deleteBtn.addEventListener("click", function(){ console.log(result.textContent.length); if (result.textContent.== "") { var text = result;textContent. var newText = String(text),slice(0; -1). result;textContent = parseFloat(newText). } if (result.textContent.length == 1) { result;textContent = ""; } })

result is area where the numbers are结果是数字所在的区域

You cannot parseFloat empty string你不能 parseFloat 空字符串

I suggest我建议

result.textContent = +newText || "";

 const result = document.getElementById("result"); const deleteBtn = document.getElementById("deleteBtn"); deleteBtn.addEventListener("click", function(){ console.log(result.textContent.length); if (result.textContent.== "") { var text = result;textContent. var newText = text,slice(0; -1). console.log(newText) // result;textContent = parseFloat(newText || ""). result;textContent = +newText || ""; } })
 <button id="deleteBtn">delete</button> <div id="result">123</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我试图设计我的地图以使其更暗,但它不起作用 - I am trying to style my map to make it darker but its not working 我正在尝试使用 React js 在电话簿应用程序上创建一个删除按钮 - I am trying to make a delete button on phonebook app with React js 我试图在同一页面上有第二个 slider 但它不起作用 - I am trying to have a second slider on the same page but its not working 我正在尝试使用javascript更改链接的颜色并且它不起作用 - I am trying to change the color of link using javascript and its not working 我正在尝试使用反应钩子 useContext() 但它不起作用 - I am trying to use the react hook useContext() but its not working 我正在尝试用 Javascript 制作一个计算器。 但它以某种方式不起作用 - I am trying to make a calculator in Javascript. But it is not working somehow 我正在尝试使用 javascript 进行表单验证,但 email 验证不起作用 - I am trying to make form validation with javascript but email validation not working 我正在尝试选中其主题复选框的tbody的所有复选框,但无法正常工作 - I am trying to tick all the checkboxes of tbody when checkbox of its thead is checked but its not working 我想添加一个手风琴,但它没有打开 - I am trying to add an accordion but its not opening 使用flask-admin和sqlalchemy; 现在我试图做一个表格来添加/删除/编辑我的表 - using flask-admin and sqlalchemy; now i am trying to make a form to add/delete/edit my table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM