python - Safari 浏览器中的下拉菜单不显示下拉元素

标签 python css django

我的下拉菜单适用于 Chrome(台式机和移动设备)和 Firefox(台式机和移动设备),但似乎不适用于 Safari(台式机)和 Chrome(平板电脑)。

这是在 Chrome 上工作的样子 enter image description here

这是它在 Safari 上的样子 enter image description here

HTML:

<button type="button" id="platform" class="btn btn-orange dropdown-toggle mr-2" data-toggle="dropdown"
                        aria-haspopup="true" aria-expanded="false">
                    Select Platform
                </button>

<div class="dropdown-menu" id="plat-form-options">
                    {% for platform in game.platform.all %}
                        <option class="dropdown-item" value="{{ platform.id }}"
                                onclick="platFormSelect('{% url 'title-updates-ajax' slug=game.slug platform_id=platform.id %}', '{{ platform }}')">{{ platform }}</option>
                    {% endfor %}
                </div>

Javascript:

 $(document).ready(function () {
            if ($("#plat-form-options option").length > 0) {
                $("#plat-form-options option")[0].click();
            }

        });


        function platFormSelect(url, platform) {
            $('#platform').text(platform);


            $.get(url, function (response) {
                        $('#updates_data').html(response);

                    })
                    .done(function () {

                    })
                    .fail(function () {

                    });

        }

最佳答案

它看起来像你的 <option>标签应该是 <a>标签,因为它们没有包裹在 <select> 中.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

试试这个:

<div class="dropdown-menu" id="plat-form-options">
  {% for platform in game.platform.all %}
      <a href="#" class="dropdown-item" value="{{ platform.id }}"
              onclick="platFormSelect('{% url 'title-updates-ajax' slug=game.slug platform_id=platform.id %}', '{{ platform }}')">{{ platform }}</a>
  {% endfor %}
</div>

关于python - Safari 浏览器中的下拉菜单不显示下拉元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55248260/

相关文章:

python - 使用 Django 将文件复制到另一个文件夹?

python - 如何覆盖 django save 方法以动态更新某些字段?

python - 处理timedelta()和datetime.now

python - LOAD DATA LOCAL INFILE sqlalchemy 和 python 到 mysql 数据库

python - 在条件 : O(n) or O(n^2)? 中调用 max 的列表理解的 Big-O

html - CSS重复背景相对于居中的html内容是固定的吗?

css - 光标在不可点击的区域是手,光标在可点击的区域

python - 如何以及在哪里从 github 安装 python 模块

python - Flask-Login 在使用 remember_me 时使用注销后仍然登录

css - 在元素列表中用 Flexbox 填充垂直空间