python - Safari 中的下拉菜单不显示下拉项目
问题描述
我的下拉菜单适用于 Chrome(台式机和手机)和 Firefox(台式机和手机),但似乎不适用于 Safari(台式机)和 Chrome(平板电脑)。
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>
推荐阅读
- mysql - Mysql:合并两个具有重叠唯一列的相似表
- javascript - 使用 jest 模拟 axios 请求
- r - 在 R 中第二次出现模式时剪切字符串向量的每个元素
- javascript - bulma框架的下拉javascript
- excel - 每当答案为零时,我需要索引函数返回空白
- function - 如何使用函数将列表中的每个元素除以 int
- python - 如何通过自动下载链接使用 Python 访问 PDF 文件?
- node.js - 跟踪用户登录次数的最佳方法
- windows - 如果笔记本电脑使用交流电源且未锁定,则用于按键的 VBscript
- r - 如何计算多次观察到的单位的斜率,不包括0