This is classical conditioning. Additionally, operant conditioning can be used to change an attitude. When you express your attitude, others may either agree or disagree, which can be interpreted as a reward or punishment, respectively. Modeling is also important in attitude change and formation. Just as we can learn many other things from watching models, we can learn our attitudes to have or not to have by observing models receive rewards or punishment for their attitudes.
People continue to smoke, even though they know it is bad for their health.
During the late 1950's Leon Festinger developed the cognitive dissonance theory to explain attitude formation and change. Festinger also theorized that, if a person could sufficiently attribute their behavior to an external influence, his dissonance would be lower and thus there would be a lesser attitude change. For a great example of this, see Supporting Studies Cognitive dissonance explains well the process of effort justification. For example, if someone pays a high price for a new car and finds the car uncomfortable, he may experience dissonance and so to reduce it, he alters his attitude about the car to be more positive. Cognitive dissonance is by no means a full-proof theory for predicting attitude change.