Example 7 Let $n(n \geqslant 2)$ be an integer. $S$ is a subset of the set $\{1,2, \cdots, n\}$, where no number in $S$ divides another, and no two numbers are coprime. Find the maximum number of elements in $S$.

 untranslated text remains unchanged.
Define the mapping $f$:
$$
S \rightarrow\left\{\left[\frac{n}{2}\right]+1,\left[\frac{n}{2}\right]+2, \cdots, n\right\},
$$
$f$ transforms $x \in S$ into $2^{k} x \in\left(\frac{n}{2}, n\right]$ (where $k$ is a non-negative integer), and the elements in the set $\left\{\left[\frac{n}{2}\right]+1,\left[\frac{n}{2}\right]+2, \cdots, n\right\}$ satisfy the condition that "no number divides another."

It is easy to see that this is an injection, because if there exist non-negative integers $k_{1}$ and $k_{2}$ such that $2^{k_{1}} x=2^{k_{2}} y$, without loss of generality, assume $k_{1} < k_{2}$. Then $2^{k_{1}} x = 2^{k_{2}} y$ implies $x = 2^{k_{2}-k_{1}} y$, which means $x$ is a multiple of $y$. Since $(x, y) \mid (f(x), f(y))$, it follows that $(f(x), f(y)) > 1$.
Thus, $f(S)$ does not contain two consecutive integers.
Therefore, $|S| \leqslant\left[\frac{\frac{n}{2}+1}{2}\right]=\left[\frac{n+2}{4}\right]$.
Moreover, when $S=\left\{k \mid k \text{ is even, } k>\frac{n}{2}\right\}$, $S$ satisfies the given conditions.
Hence, the maximum value of $|S|$ is $\left[\frac{n+2}{4}\right]$.