We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当一个事物受到两个及以上事物或者变量的干扰时,将其判断逻辑抽离出来独立进行操作。
可以用闭包进行元素缓存
var mediator = (function () { var colorSelect = document.getElementById('colorSelect'), memorySelect = document.getElementById('memorySelect'), numberInput = document.getElementById('numberInput'), colorInfo = document.getElementById('colorInfo'), memoryInfo = document.getElementById('memoryInfo'), numberInfo = document.getElementById('numberInfo'), nextBtn = document.getElementById('nextBtn'); return { changed: function (obj) { var color = colorSelect.value, // 颜色 memory = memorySelect.value,// 内存 number = numberInput.value, // 数量 stock = goods[color + '|' + memory]; // 颜色和内存对应的手机库存数量 if (obj === colorSelect) { // 如果改变的是选择颜色下拉框 colorInfo.innerHTML = color; } else if (obj === memorySelect) { memoryInfo.innerHTML = memory; } else if (obj === numberInput) { numberInfo.innerHTML = number; } if (!color) { nextBtn.disabled = true; nextBtn.innerHTML = '请选择手机颜色'; return; } if (!memory) { nextBtn.disabled = true; nextBtn.innerHTML = '请选择内存大小'; return; } if (((number - 0) | 0) !== number - 0) { // 输入购买数量是否为正整数 nextBtn.disabled = true; nextBtn.innerHTML = '请输入正确的购买数量'; return; } nextBtn.disabled = false; nextBtn.innerHTML = '放入购物车'; } } })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
中介者
The text was updated successfully, but these errors were encountered: