<script src="../js/jquery-3.4.1.min.js"></script>
<script>
window.onload = function () {
let key = $('.keyboard div');
let keyStr = ''
key.click(function () {
let str = ''
let eleStr = $(this).html() == '删除' ? '' : $(this).html(); // 是否删除
if(keyStr.length <= 0 && eleStr == '0') return; // 首位不能为0
keyStr = keyStr + eleStr; // 拼接点击的数字
if(eleStr == '') keyStr = keyStr.substr(0, keyStr.length - 1); // 删除
for (let i = 0; i < keyStr.length; i++) { // 遍历
if (keyStr[i] == '.') { // 判断是否为.
if (str.indexOf('.') == -1) str = str + keyStr[i]; // 是.并且其中不存在
} else str = str + keyStr[i]; // 不是.就拼接
}
showPrice($('#show-price'), str); // 渲染
})
function showPrice(ele, str) {
let htmlStr = ''
for (let i = 0; i < str.length; i++) {
htmlStr = htmlStr + `<span>${str[i]}</span>`
}
ele.html(htmlStr);
}
</script>