Chemical enrichment and the origin of the colour-magnitude relation of elliptical galaxies in a hierarchical merger model