플레이 프레임 워크 2.3.8을 사용하고 버튼 옆에있는 특정 텍스트 값을 변경하려고합니다. 버튼은 생성 된 목록을 통해 동적으로 추가되므로 버튼 옆에있는 올바른 텍스트를 찾을 수 없습니다.
이것은 다음과 같습니다.
내 뷰 클래스는 questionList: List[Question]
반복하고 여러 버튼을 내 html에 넣는 질문 목록을 가져 옵니다.
@for(question <- questionList){
<!-- Questions -->
<li class="list-group-item" >
<button type="button" class="btn btn-default" id="upvoteButton"
value="voteUp" style="width: 30px; height: 30px; text-align: center; vertical-align: center;">
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true" style="color:orange"></span>
</button>
<span class="num"> @question.voteScore </span>
(...)
클래스에서 "num"은 버튼 클릭으로 변경하려는 질문에 대한 실제 voteScore입니다. 버튼이 생성되어 모두 동일한 ID 태그를 갖기 때문에 ID 태그가 도움이되지 않습니다 (참고 : 실제로 첫 번째 ID 만 작동합니다. 첫 번째 버튼이 고유 한 ID를 가져 오는 것 같나요?).
지금까지 내 접근 방식 :
num
자체를 클릭하면 값을 변경할 수 있습니다.
$(document).ready(function(){
$(document).on('click', '.num', function(){
$(this).html(111);
});
});
그러나 버튼 클릭으로이 작업을 수행하려고하면 실패합니다.
$(document).ready(function(){
$(".btn-default").click(function(){
$(this).slideUp().slideDown();
console.log($('.num').html());
});
});
어떤 버튼을 클릭하더라도 console.log의 출력은 항상 76입니다. 올바른 번호에 연결된 버튼을 찾을 수 없습니다. 어떻게해야합니까?
이 시도:-
$(".btn-default").click(function(){
$(this).slideUp().slideDown();
$(this).next('.num').html('111');
});
또는 시도해 볼 수도 있습니다.
$(".btn-default").click(function(){
$(this).slideUp().slideDown();
$(this).parent('li').find('.num').html('111');
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다