If your roving toddler does head toward an unacceptable or dangerous play object, calmly say "No" and either remove your child from the area or distract him or her with another activity.
It's important to not spank, hit, or slap your child. At this age, kids are unlikely to be able to make a connection between the behavior and physical punishment. The message you send when you spank is that it's OK to hit someone when you're angry. The American Academy of Pediatrics (AAP) discourages spanking, which is no more effective than other forms of discipline, such as timeouts.