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

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?

主站蜘蛛池模板: 郴州市| 顺平县| 天水市| 横山县| 宝丰县| 海兴县| 双城市| 枣阳市| 阳高县| 信丰县| 郓城县| 雷波县| 思茅市| 巴彦淖尔市| 临湘市| 嘉鱼县| 苍溪县| 白河县| 德江县| 宝丰县| 太仆寺旗| 夹江县| 临颍县| 历史| 宽城| 哈巴河县| 元谋县| 鄢陵县| 诸暨市| 宁波市| 苗栗县| 宣汉县| 苏尼特左旗| 安泽县| 铁岭县| 东山县| 五寨县| 房山区| 莱芜市| 化州市| 永善县|