这就是我要做的(使用jQuery的
data()
功能)(
demo
)
<div class="results">
<div class="results-wrapper">
<div class="form-item webform-component webform-component-display" id="webform-component-fieldset-1--question-1"
data-answer="C">C. I do not know</div>
</div>
</div>
<script>
var updateAnswer = function (question) {
var answer = question.data('answer');
if (answer === 'A') {
$('.results-wrapper').hide();
$('.results').append('<div class="popup">User Selected A. Yes, for the first answer.</div>');
} else if (answer === 'B') {
$('.results-wrapper').hide();
$('.results').append('<div class="popup">User Selected B. No, for the first answer.</div>');
} else if (answer === 'C') {
$('.results-wrapper').hide();
$('.results').append('<div class="popup">User Selected C. I do not know, for the first answer.</div>');
} else {
alert('something went wrong');
}
}
updateAnswer($('#webform-component-fieldset-1--question-1'));
</script>