I think the proof in for Lemma 2.1 in Joe Harris's book Algebraic Geometry, A First Course, does not work. (The statement is on Page 19, and the proof on Page 61.) The proof fails because that $gk_\alpha=h_\alpha$ is valid on $U_\alpha$ only, while the last but one equation on Page 61 must work on the whole domain of the regular function.
I have been trying to give a proof or find a counterexample. The proof for the case in which the variety is irreducible is easy. In the reducible case, I managed to reduce the question to the following one:
Suppose we are working with a algebraically closed field K and a regular function on an open subset of an affine variety is by definition a function locally representable as $F/G$, with $F,G\in K[x_1,...,x_n]$, and $G$ non-vanishing in a neighbourhood. Suppose we have a variety $V\subset \mathbb A^n$, $V=\cup V_i$ is the decomposition into irreducible components. Suppose we have $F,G\in K[x_1,...,x_n]$, such that $G$ divides $F$ in each $K[x_1,...,x_n]/I(V_i)$. Does it follow that $G$ divides $F$ in $K[x_1,...,x_n]/I(V)$?
Intuitively, this means that $I(F)~$ contains $I(G)~$ in each component implies the same thing on the whole variety. It seems quite reasonable. But I am not sure whether there will be any abnormality when considering "multiplicities".
P.S.You may assume that $\cap V_i$ is nonempty, this is adequate for my purpose. Though I don't think this further assumption will help.