부트스트랩이 있는 루프를 사용하여 여러 이벤트 추가 (Using a loop with bootstrap to add multiple events)


문제 설명

부트스트랩이 있는 루프를 사용하여 여러 이벤트 추가 (Using a loop with bootstrap to add multiple events)

공지사항을 작성할 수 있는 웹사이트를 디자인 중입니다.공지 내용의 그림

더하기 기호를 클릭하면 창이 나타납니다. 공지 내용 자세히 보기

각 공고의 정보가 각 더하기 기호. 하지만, 각 더하기 기호가 대신 첫 번째 알림(테스트 2)의 정보를 표시하는 문제가 발생했습니다. 내 코드는 다음과 같습니다.

<% @announcements.each do |announcement| %>
<!‑‑ sets each announcement to be 3 per row ‑‑>
<div class="col‑md‑4 announcement‑div">
    <!‑‑ Title and subject of the announcement ‑‑>
    <p>
        <span class="topBottom"><%= announcement.subject %></span>
        <br>
        <%= announcement.created_at.strftime("%m/%d %Y %I:%M %p") %>
    </p>
    <!‑‑ Stars to signify important events ‑‑>
    <% if announcement.importance %>
        <h2>&#9733;</h2>
    <% end %>
    <!‑‑ The plus sign button ‑‑>
    <button type="button" class="btn popup‑btn">+</button>
    <!‑‑ Current announcement Display Code ‑‑>
    <div id="announcementDisplayModal" class="modal">
        <span id="announcementDisplayModal‑close" class="close" onclick="document.getElementById('announcementDisplayModal').style.display='none'">&times;</span>
        <div class="modal‑content well modal‑dimensions">
            <h3 class="cardinal borders"> <%= announcement.subject %> </h3>
        </div>
    </div>
</div>
<% end %>

자바스크립트:

<script>
// Get the modal
var modal = document.getElementById('announcementDisplayModal');

$('.popup‑btn').click(function() {
    modal.style.display = "block";
});

// Get the <span> element that closes the modal
var span = document.getElementById("announcementDisplayModal‑close");

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
    modal.style.display = "none";
}
</script>

수정 방법에 대한 아이디어가 있습니까? getElementById에서 클래스 유형별로 요소를 가져오고 ID를 클래스로 변경하려고 시도했지만 작동하지 않았습니다.


참조 솔루션

방법 1:

Okay, one thing you need to notice is the ID of an element in a document must be unique. But in this case you are repeating announcementDisplayModal.

So to fix this problem instead of using an ID selector, try this,

instead of,

$('.popup‑btn').click(function() {
    modal.style.display = "block";
});

try,

$('.popup‑btn').click(function() {
    $(this).next().css('display', 'block');
});

(by S Mittalakhil.cs)

참조 문서

  1. Using a loop with bootstrap to add multiple events (CC BY‑SA 2.5/3.0/4.0)

#SASS #html #ruby-on-rails #bootstrap-modal #javascript






관련 질문

나침반 SCSS 글꼴 URL 구성 문제 (Compass SCSS font-url configuration issue)

SASS: normalize.css가 작동하지만 컴파일된 CSS 파일에 표시되지 않습니까? (SASS: normalize.css works, but does not show up in compiled CSS file?)

CSS zurb 기초 및 dhtmlx (CSS zurb foundation and dhtmlx)

_settings.scss의 변수는 주석 처리되지 않은 상태로 컴파일됩니다. (Variables in _settings.scss are compiled as uncommented)

Grunt 및 Compass와 함께 node-normalize-scss 사용 (Using node-normalize-scss with Grunt and Compass)

부트스트랩이 있는 루프를 사용하여 여러 이벤트 추가 (Using a loop with bootstrap to add multiple events)

특정 파일에 대한 앵귤러 로더 재정의 (Override angular loaders for specific files)

상자 그림자가 있는 여러 겹치는 이미지에 대한 CSS (CSS for multiple overlapping images with box shadow)

중앙에 div를 만든 후 div를 만듭니다. (Make a div, after centered div)

소품과 값 사이에 공백을 적용하기 위한 Sass linting 규칙이 VS Code에서 잘못 작동합니까? (Is the Sass linting rule for enforcing a space between the prop and value working incorrectly with VS Code?)

Next.js를 사용하는 scss의 클래스 이름 규칙 (Class names convention for scss using Next.js)

새 프로젝트를 만드는 동안 Angular CLI에서 sass를 선택했습니다. 이제 sc로 변경하고 싶습니다. 어떻게 할 수 있습니까? (I chose sass in angular CLI while i was creating the new project. i want to change it to scss now. how can i do that?)







코멘트