Bonjour Ashraf,
Actually it's a bit more complicated!
Here 'un pantalon' means 'a pair of trousers'. Depending on context, you could use l' or en :
J'achète un pantalon. J'en achète un.
(I'm buying a pair of trousers. I'm buying one.)
J'ai acheté un pantalon. Je l'adore !
(I bought a pair of trousers. I love it!)
J'achète des pantalons. J'en achète.
(I'm buying some pairs of trousers. I'm buying some.)
You can only use en on its own when talking about a vague or uncountable quantity (some).
I hope that's helpful!