Let's talk about the "temperature on the moon". That phrase has led to a lot of confusion. You have no doubt heard that the temperature on the Moon varies from -250F up to 250F. I live in Texas, and in the summertime, the temperature gets up over 100F, so standing on the Moon must be like standing in an oven, right?
No.
If, on a hot summer day here in Texas, I walk out on the sidewalk barefoot, it's hot enough to cause pain. If I step onto the asphalt street, I will blister my feet. Why? 100F is less than two degrees above normal body temperature. The solid pavement is hotter than the transparent air because it absorbs more radiant energy from the sunlight. The light-colored concrete sidewalk may heat-up to 120-140F. The darker asphalt may get up to 180F or more.
When we ask, "what is the temperature outside?" we are asking about the ambient temperature of the air. On the Moon, there is no air, so when we ask about the temperature there, we are asking about the temperature of a specific object on the surface; a patch of dirt, a rock, a camera or an astronaut's spacesuit (and specifying whether it is the side facing towards or away from the Sun). Note that this varies: In my above example, the sidewalk was ~130F, but the asphalt was 180+ F. When a textbook says that it gets up to 250F on the Moon, it is referring to the surface of a black, solid object with its face perpendicular to the Sun at local noon.
The actual lunar surface is not black: It's about the same shade as asphalt (not the fresh-laid black stuff, but rather the dark/medium grey color it fades to after a few years). It heats up to roughly 200F. Mind you, the Moon is the same average distance from the Sun as the Earth. All things being equal, lunar regolith and asphalt should reach the same temperature. However, the asphalt is cooled somewhat because the air in contact with the pavement conducts away some of the heat (we can see it doing this: it causes the shimmering effect when we look across a hot parking lot). Also, daylight only last ~12 hours on Earth, but it's 14 days from sunrise to sunset on the Moon.
I said before that the pavement here in Texas can get up to ~180F. However, on a summer day I can go outside and walk on it barefoot with no discomfort. How? It's simple: I do it at 8:00am, before it gets anywhere near that hot. The Apollo astronauts did the same thing: They landed when the rising sun was only ~10 degrees above the horizon and the surface temperature was ~30F. When they left three days later (on the longest missions), the sun was still only half-way up the sky, and the surface temperature was a bit over 100F (yes, NASA did have the technology to make insulated shoes in the 1960s ).
(Allow me to state the blindingly obvious: The surface starts out cold because it has spent all night radiating its heat into space. As someone else already pointed out, when a surface is in the sun, it absorbs light based on its reflectivity (more reflective absorbs less energy) and its angle to the sun (a perpendicular angle to the light absorbs more than an oblique angle). When the same surface is shaded from the sun, it radiates heat as efficiently as it absorbs it - a black surface radiates faster than a light one.)
For astronauts, heat management is a crucial issue that requires careful engineering, whether they are on the Moon or in Earth orbit - Remember, they are at the same average distance from the Sun. In fact, the Earth is more reflective than the Moon, so astronauts & spacecraft in Earth orbit get more reflected energy than those on the Moon (even though the surface is much further away, there's a lot more area doing the reflecting). For spacecraft & spacesuits (which can be thought of as mini-spacecraft), the engineering solution is basically the same: Keep as much of the outside heat out and control the heat that's being generated on the inside to maintain comfortable levels.
Outside heat from direct & reflected sunlight is kept out by using a reflective outer layer, backed up by layers of insulation. When you look at the flimsy-looking outer covers of the Lunar Module, you're only seeing the reflective skin that covers the actual structural members and pressure vessels beneath. Interestingly, Middle Eastern nomads developed the same principle centuries ago: Those volumous white robes they wear serve the same function, and work better than shorts and a t-shirt to keep them cool in the desert.
Inside, heat is generated by electronics and by the astronauts themselves. On full-size spacecraft, most of the heat comes from electronics, and any excess goes to shielded radiators on the hull (on Apollo 13, when they lost power, they shut down the electronics and therefore their main heat source, which is why it got so cold). Men doing geology on the Moon, and building the International Space Station in orbit are basically doing heavy work for hours in an airtight rubber suit. Beneath the rubber, they wear something like long underwear that has a whole network of tubes. They pump water through the tubes to something called a porous-plate sublimator, which carries the heat away to space.
The smaller pieces of equipment on the Moon, such as cameras and experiment packages mainly relied on reflective outer casings. In these cases, keeping the dark lunar dust off of them was a major concern. On the EVA videos, you can hear some exasperation from the astronauts after the umpteenth request from Houston to dust-off the TV camera because it's overheating. Of course, the astronauts and the still cameras they carried were almost constantly turning this way and that, so individual surfaces spent as much time facing away from the Sun as towards it.
Hopefully this helps clear things up.