- Mastering JavaScript Functional Programming
- Federico Kereki
- 177字
- 2021-07-02 22:41:09
The problem - do something only once
Let's consider a simple, but common situation. You have developed an e-commerce site: the user can fill their shopping cart, and at the end, they must click on a BILL ME button, so their credit card will be charged. However, the user shouldn't click twice (or more) or they would be billed several times.
The HTML part of your application might have something like this, somewhere:
<button id="billButton" onclick="billTheUser(some, sales, data)">Bill me</button>
And, among the scripts you'd have something similar to this:
function billTheUser(some, sales, data) {
window.alert("Billing the user...");
// actually bill the user
}
Assigning the events handler directly in HTML, the way I did it, isn't recommended. Rather, in unobtrusive fashion, you should assign the handler through code. So... Do as I say, not as I do!
This is a very barebones explanation of the problem and your web page, but it's enough for our purposes. Let's now get to think about ways of avoiding repeated clicks on that button... How can we manage to avoid the user clicking more than once?
- 程序員面試筆試寶典
- 云原生Spring實戰(zhàn)
- Linux網(wǎng)絡(luò)程序設(shè)計:基于龍芯平臺
- Visual C++串口通信技術(shù)詳解(第2版)
- SAS數(shù)據(jù)統(tǒng)計分析與編程實踐
- INSTANT Passbook App Development for iOS How-to
- Java零基礎(chǔ)實戰(zhàn)
- Java 從入門到項目實踐(超值版)
- 一步一步跟我學(xué)Scratch3.0案例
- OpenCV Android開發(fā)實戰(zhàn)
- 精通Spring:Java Web開發(fā)與Spring Boot高級功能
- Java高手是怎樣煉成的:原理、方法與實踐
- Microsoft Windows Identity Foundation Cookbook
- Learning ROS for Robotics Programming
- Lync Server Cookbook