Potassium and magnesium are the major cations inside cells, while sodium is the major extracellular cation. Phosphate and protein are the major intracellular anions, with chloride and bicarbonate outside.
Movement of specific ions is the basis of the action potential. It depends on two major factors:
concentration gradients and transmembrane potentials (voltage) are important factors in attracting or repelling given ions. For example, the low concentration of sodium inside the cell, as well as a negative resting potential, combine to drive sodium entry into cells.
ion channels are important means of ion entry. but there is a lot more to the story than this. There is a great book - Cells, Gels, and the Engines of Life - which is worth a read for those interested in ion flux across membranes.
Sodium and chloride is absorbed in the colon, potassium is secreted. While Bicarbonate appears to be absorbed also, it is being broken down into water and carbon dioxide.
Diarrhea whille therefore cause a loss of bicarbonate, resulting in metabolic acidosis, and posassium, causing cardiac arrhythmias.