Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.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
Html 在引导模式中,通过按钮从图像选择中更改背景图像_Html_Css_Bootstrap Modal - Fatal编程技术网

Html 在引导模式中,通过按钮从图像选择中更改背景图像

Html 在引导模式中,通过按钮从图像选择中更改背景图像,html,css,bootstrap-modal,Html,Css,Bootstrap Modal,我已经创建了一个编辑按钮,它打开了一个包含一组图像的模式,在我选择其中一个图像后,我想通过一个按钮将其设置为背景。当你想改变背景时,就像谷歌浏览器主页上的编辑按钮一样。但我真的不知道如何修改背景:图片url 以下是背景的css: 以下是html: 我找到了我想要的答案,但我放弃了设置背景按钮: 我在head中创建并添加了以下javascript: 我在页眉中添加了backgroundXD id,并在脚本中使用它来更改masthead css的背景: 我还将onclick添加到输入中,通过单击mo

我已经创建了一个编辑按钮,它打开了一个包含一组图像的模式,在我选择其中一个图像后,我想通过一个按钮将其设置为背景。当你想改变背景时,就像谷歌浏览器主页上的编辑按钮一样。但我真的不知道如何修改背景:图片url

以下是背景的css:

以下是html:


我找到了我想要的答案,但我放弃了设置背景按钮:

我在head中创建并添加了以下javascript:

我在页眉中添加了backgroundXD id,并在脚本中使用它来更改masthead css的背景:

我还将onclick添加到输入中,通过单击modal中的首选图像来更改背景图像:


什么版本的引导?你确定不想使用基于jQuery的方法吗?我使用的是3.4.0版本,但是我如何编辑和添加答案,这不再重要了。我仍然感谢你的时间和关注
.masthead {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 35rem;
    padding: 15rem 0;
    background: linear-gradient(to bottom, rgba(22, 22, 22, .3) 0, rgba(22, 22, 22, .7) 75%, #161616 100%), url(../img/planet_sky.jpg);
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: scroll;
    background-size: cover
}
<header class="masthead">

    <!--Editing button-->
    <div align="right">
        <button type="button" class="btn btn-primary mx-auto" data-toggle="modal" data-target="#changeBackground">
        <span class="glyphicon glyphicon-pencil"></span></button>
    </div>      

        <!-- Modal -->
        <div class="modal fade" id="changeBackground" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">

                    <div class="modal-header text-center">
                        <h4 class="modal-title w-100 font-weight-bold">Select background</h4>

                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                        </button>
                    </div>

                    <div class="modal-body">

                        <input type="image" src="https://s.ftcdn.net/v2013/pics/all/curated/RKyaEDwp8J7JKeZWQPuOVWvkUjGQfpCx_cover_580.jpg?r=1a0fc22192d0c808b8bb2b9bcfbf4a45b1793687" height="200" width="230" style="padding-right: 3px;padding-bottom: 3px;"  class="img">

                        <input type="image" src="https://pennyandjohninoz.files.wordpress.com/2011/10/icons-of-australia-3-sydney-opera-house.jpg" height="200" width="230" style="padding-right: 3px;padding-bottom: 3px;"  class="img">

                    </div>

                    <div class="modal-footer d-flex justify-content-center">
                        <button class="btn btn-primary mx-auto">Set background <i class="fas fa-paper-plane-o ml-1"></i></button>
                    </div>

                </div>
            </div>
        </div>

</header>
    <script>
    function changeBackground1(imageUrl){
        document.getElementById('backgroundXD').style.backgroundImage = "linear-gradient(to bottom, rgba(22, 22, 22, .3) 0, rgba(22, 22, 22, .7) 75%, #161616 100%), url("+imageUrl+")";
    }
    </script>
<header class="masthead" id="backgroundXD">
...
</header>
<input onclick="changeBackground1('https://s.ftcdn.net/v2013/pics/all/curated/RKyaEDwp8J7JKeZWQPuOVWvkUjGQfpCx_cover_580.jpg?r=1a0fc22192d0c808b8bb2b9bcfbf4a45b1793687')"
    type="image" src="https://s.ftcdn.net/v2013/pics/all/curated/RKyaEDwp8J7JKeZWQPuOVWvkUjGQfpCx_cover_580.jpg?r=1a0fc22192d0c808b8bb2b9bcfbf4a45b1793687" height="150" width="230" style="padding-right: 3px;padding-bottom: 3px;"  class="img">

<input onclick="changeBackground1('https://pennyandjohninoz.files.wordpress.com/2011/10/icons-of-australia-3-sydney-opera-house.jpg')"
    type="image" src="https://pennyandjohninoz.files.wordpress.com/2011/10/icons-of-australia-3-sydney-opera-house.jpg" height="150" width="230" style="padding-right: 3px;padding-bottom: 3px;"  class="img">