2017-11-24 3 views
1

프로그래밍을 처음 사용하고 몇 가지 시도하고 있습니다. 그 순간은 지금 막 붙어있어, 나는 지금 웹 페이지를 만들고있다. 지금 내가 원하는 것은 드롭 다운 메뉴에서 항목을 클릭하면 iFrame 소스가 원하는 링크로 변경된다는 것입니다. 여기서 내가 뭘 잘못하고 있니?드롭 다운에서 iFrame 변경

<div class="dropdown droplist"> 
    <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" 
     aria-expanded="false"> 
     Choose List 
    </button> 
    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> 
     <a class="dropdown-item" href="#" id="#action-1">Party</a> 
     <a class="dropdown-item" href="#">Furutre</a> 
     <a class="dropdown-item" href="#">Late Night</a> 
    </div> 
</div> 
<script> 
    jQuery("#action-1").click(function (e) { 
     function switchView() { 
      document.getElementById("spotifycontainer").src = 
       'https://open.spotify.com/embed/user/21sbumll6xursi72kr7vkspay/playlist/4VEIFU2doL7TdnolXXFd70'; 
     } 
     e.preventDefault(); 
    }); 
</script> 
<div> 
    <iframe src="" class="spotifylist" width="1280" height="720" frameborder="0" allowtransparency="true" id="spotifycontainer"> 
    </iframe> 
</div> 

답변

0

jQuery를 가져 오지 않고 사용하려고하는 것 같습니다.
편리한 오류 메시지를 확인하려면 항상 콘솔을 열어야합니다.

function switchView(mode){ 
    let spotifyContainer = document.getElementById("spotifycontainer"); 

    if (mode == 'party'){ 
    spotifyContainer.src='https://open.spotify.com/embed/user/21sbumll6xursi72kr7vkspay/playlist/4VEIFU2doL7TdnolXXFd70'; 
    } 
    if (mode == 'future'){ 
    spotifyContainer.src = 'https://open.spotify.com/embed/user/21sbumll6xursi72kr7vkspay/playlist/4VEIFU2doL7TdnolXXFd70'; 
    } 
} 
+0

어떤 흔적 및 오류 나는 당신을 감사처럼 그럼 당신은 보이는 switchView 방법을 만들 수있는이

<div class="dropdown-menu" aria-labelledby="dropdownMenuButton"> <a class="dropdown-item" href="#" onClick="switchView('party')">Party</a> <a class="dropdown-item" href="#" onClick="switchView('future')">Furutre</a> <a class="dropdown-item" href="#" onClick="switchView('lateNight')">Late Night</a> </div> 

같은 JS 함수를 호출하여 HTML로 onClick을 사용할 수 있습니다 이 방법으로도 그렇게했습니다. 하지만 고마워요! –

관련 문제