typescript - Ionic 3 - 打字稿错误:算术操作数必须是“任何”、“数字”或枚举类型
问题描述
当用户单击类似按钮以增加数字时,我有一个单击操作,但是在构建或运行 ionic 应用程序时,我遇到了打字稿错误,有人可以帮我解决这个问题吗?
Typescript Error
An arithmetic operand must be of type 'any', 'number' or an enum type.
src/pages/comments/comments.ts
document.getElementById("like-" + commentid).innerHTML++
在comments.ts
likedislike(type,commentid) {
if(type === 'like') {
document.getElementById("like-" + commentid).innerHTML++
}
}
解决方案
尝试使用Number()
将内部 html 字符串转换为数字。
var x = document.getElementById("like-" + commentid).innerHTML;
document.getElementById("like-" + commentid).innerHTML = Number(x) + 1
虽然在 Ionic 中使用 Angular 数据绑定来做到这一点要好得多......
推荐阅读
- c++ - C++ 警告:使用未使用的参数覆盖虚函数
- vue.js - VueJS:在 v-if 中直接改变 prop 与 this.[prop]
- css - CSS中数字的有效范围是多少
- python-3.x - 如何使用千位分隔符格式化 plt.axhline 标签?
- r - 比较 R 中两个统计检验之间的功效
- python - 如何调用或导入python类文件
- python - Python 数据类生成哈希并排除不安全字段
- ansible - 我们可以使用 Ansible 模块计算 ESXi 主机的实时内存和存储利用率吗?
- unit-testing - 从 Kotlin 中的 GradientDrawable 获取颜色
- xml - 如何在 xslt 中放置正确的条件