클릭 기능 (이미 Jquery ...에 대해 수행)을 기반으로 img 요소에 "selected"라는 CSS 클래스 이름을 추가하거나 제거하기위한 PROTOTYPE 스크립트를 그림하지만 프로토 타입에 있어야합니다. 그리고 그것은 나를 미치게합니다. 캔트프로토 타입이있는 클래스를 추가 또는 제거
내 원래 코드 (마 젠토 저장소) jQuery를 들어
<div class="block block-poll">
<div class="block-title">
<strong><span><?php echo $this->__('Community Poll') ?></span></strong>
</div>
<form id="pollForm" action="<?php echo $action ?>" method="post" onsubmit="return validatePollAnswerIsSelected();">
<div class="block-content">
<p class="block-subtitle"><?php echo $this->htmlEscape($poll->getPollTitle()); ?></p>
<?php if($poll_answers): ?>
<ul id="poll-answers">
<?php foreach($poll_answers as $answer): ?>
<li>
<input type="radio" name="vote" style ="display:none;" class="radio poll_vote" id="vote_<?php echo $answer->getId() ?>" value="<?php echo $answer->getAnswerId() ?>" />
<?php
$stripped = $answer->getAnswerTitle();
$stripped_final = str_replace(" ", "_", strtolower($stripped)); //Value (simplified)
?>
<span class="label"><label for="vote_<?php echo $answer->getId() ?>"><img src="http://www.passione.pt/media/poll/<?php echo $stripped_final; ?>.png" id="chooser" class="chooser" alt="<?php echo $this->htmlEscape($answer->getAnswerTitle()) ?>" onClick="document.getElementById('vote_<?php echo $answer->getId() ?>').checked =true;"/></label></span>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('poll-answers');</script>
<?php endif; ?>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Vote') ?>" class="button"><span><span><?php echo $this->__('Vote') ?></span></span></button>
</div>
</div>
</form>
</div>
<?php endif; ?>
입니다 ....이 프로토 타입을 위해 일합니다.
프로토 타입 1.7을 변형 할 수 있습니까? ...? (테스트되지 않은)이 클릭 핸들러의
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
var Chooser = $('#poll-answers img');
Chooser.click(function() {
$('.chooser').removeClass('selected');
if(!Chooser.hasClass('selected')) {
$(this).addClass('selected');
} else {
$(this).removeClass('selected');
}
});
</script>
jQuery에서 얻은 것을 보여주고 Protoype으로 변환합니다. – glortho
질문에 Jquery의 원본 코드를 추가했습니다. 프로토 타입을 원해. – Divisum
다음 예제를 시도해보십시오. http://www.tutorialspot.com/prototype/prototype_element_addclassname.htm – Alex