Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在下拉菜单上更改iFrame单击_Javascript_Html_Bootstrap 4 - Fatal编程技术网

Javascript 在下拉菜单上更改iFrame单击

Javascript 在下拉菜单上更改iFrame单击,javascript,html,bootstrap-4,Javascript,Html,Bootstrap 4,我是编程新手,我正在尝试一些东西。 事情是现在我卡在此刻,我正在做一个网页的时刻。 我现在想要实现的是,如果单击下拉菜单中的某个项目,它会将iFrame源更改为我想要的链接。我做错了什么 <div class="dropdown droplist"> <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown"

我是编程新手,我正在尝试一些东西。 事情是现在我卡在此刻,我正在做一个网页的时刻。 我现在想要实现的是,如果单击下拉菜单中的某个项目,它会将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>

选择列表
jQuery(“#action-1”)。单击(函数(e){
函数switchView(){
document.getElementById(“spotifycontainer”).src=
'https://open.spotify.com/embed/user/21sbumll6xursi72kr7vkspay/playlist/4VEIFU2doL7TdnolXXFd70';
}
e、 预防默认值();
});

您似乎试图在不导入jQuery的情况下使用它
始终确保打开控制台以查看方便的错误消息

您可以在html中使用
onClick
来调用类似这样的JS函数

<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>
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';
    }
}

谢谢你的一些线索和错误,我也是这样做的。但是谢谢你,先生!!!