If your cat frequently attacks your ankles, most likely you are reinforcing the behavior by giving him the attention he’s craving. Sure, cats need to play, but an ankle is not an appropriate plaything. So how do you get him to stop?
Make sure that he is getting multiple play sessions each day. Never use your hands as a toy. Encourage him to pounce on the toy by dragging it away from him. Follow the last catch with either food or a treat. Make sure your cat has plenty of places to climb onto, cat scratchers and toys to play with.
The most important thing to reduce the behavior is to give him a timeout when he gets overstimulated and attacks. Block his view of your ankles with an object or cardboard, go into another room and close the door. Keep a timeout super short; a few seconds is plenty. Your cat will soon learn that when he attacks, his favorite person/people disappear and stop attacking you.