요소에 클래스를 추가 할 수 있도록 일부 정보를 자바 스크립트에 전달하기 위해 PHP 모델 함수를 사용하고 있습니다.
자바 스크립트에서 다음과 같이 보입니다 (라 라벨 4의 블레이드 구문입니다).
@if(Auth::user())
<?php $artist_likes = Fanartist::profile_fan_likes(Auth::user()->id); ?>
@foreach($artist_likes as $like)
$("#{{$like->id}}").addClass('individual-heart-hover');
@endforeach
@endif
이것은 요소입니다.
<span class="fa-stack">
<i class="fa fa-circle-o fa-stack-2x"></i>
<i class="fa fa-heart fa-stack-1x individual-heart" id="{{$artist->id}}"></i>
</span>
페이지 소스를 살펴보면 요소의 ID와 # like-> id 요소가 모두 동일한 숫자로 렌더링되지만 (해야하는대로) 클래스가 요소에 추가되지 않는 것을 알 수 있습니다. 내가 뭔가를 놓치고 있습니까? 감사합니다.
HTML에서 숫자 전용 ID를 사용하지 마십시오.
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다