A peg works when a central bank has enough of the foreign currency that they can credibly offer to exchange to and from the local currency at a fixed ratio. Since the US Dollar is a huge major reserve currency around the world, most foreign central banks, particularly in countries that export to us, are able to do this, if they choose to.
Why they would want to do so is a more difficult question.
can you clarify on the "enough" part? how much?
Enough means, well, enough. If you run out, it is bad and the peg is broken.
But, if you control your local currency, and are a net exporter to the US, you can run it until political pressure forces you to stop doing it.
Consider China. They control their national currency, so they can always buy dollars and sell Renminbi, because they can create Renminbi out of thin air. They can also sell dollars and buy Renminbi, because as a net exporter to the US, they always have more dollars coming in than they need.
For an overview of how a currency peg works in practice, see this article.
http://www.marketskeptics.com/2009/01/hyperinflation-will-begin-in-china-and.htmlI'm not sure about the conclusions they draw, but the first diagram is worth a thousand words in understanding how it all fits together.