官术网_书友最值得收藏!

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?

主站蜘蛛池模板: 河津市| 宜城市| 阳朔县| 崇礼县| 婺源县| 建德市| 交城县| 丽水市| 怀宁县| 鄯善县| 察隅县| 遵义市| 义马市| 彭州市| 花莲市| 双鸭山市| 汉沽区| 咸宁市| 峨山| 获嘉县| 高平市| 绥德县| 交口县| 海盐县| 蕉岭县| 凭祥市| 疏附县| 新绛县| 会泽县| 蒙自县| 墨竹工卡县| 乡城县| 庆阳市| 甘洛县| 盐城市| 方正县| 荆州市| 云南省| 河西区| 固安县| 门头沟区|