【问题标题】:display all option in select without click在不点击的情况下显示选择中的所有选项
【发布时间】:2021-11-15 15:45:38
【问题描述】:

伙计们,我需要你的帮助 this is what i want in front-end to mobile device

but on mobile

here is my code

<style>
    select {
        background-color: transparent;
        border: none;
        margin: 0;
        width: 100%;
        font-family: inherit;
        font-size: 14;
        cursor: inherit;
        line-height: inherit;
        outline: none;
        text-align: center;
        height: 90;
    }

    select option {
        margin-top: 10;
    }
</style>
<div class="select m-auto">
                <select id="standard-select" name="bahasa" multiple>
                    <option value="id">Bahasa Indonesia</option>
                    <option value="en">Inggris</option>
                    <option value="viet">Vietnamese</option>
                </select>
            </div>

【问题讨论】:

  • 在手机屏幕上看起来工作正常!尝试其他浏览器
  • 使用“选择多个”是否有意义,因为用户只会选择一种语言?也许考虑使用单个选择或显示链接列表?
  • 我怀疑您将不得不实现自己的 select 版本,因为(至少在我使用的 IOS 上)您无法模拟 select 上的点击事件,并且 multiple 和 size 不起作用。跨度>

标签: html css select frontend


【解决方案1】:

请注意,大小或倍数不受移动设备的尊重,但在台式机上可以正常工作

你可以试试 - overflow:auto;

 select {
        background-color: transparent;
        border: none;
        margin: 0;
        width: 100%;
        font-family: inherit;
        font-size: 14;
        cursor: inherit;
        line-height: inherit;
        outline: none;
        text-align: center;
        overflow:auto;
    }
<div class="select m-auto">
                <select id="standard-select" name="bahasa" multiple>
                    <option value="id">Bahasa Indonesia</option>
                    <option value="en">Inggris</option>
                    <option value="viet">Vietnamese</option>
                </select>
            </div>

【讨论】:

  • 这会在我的 IOS 设备上显示文本“0 项”
  • 我发现显示所有选项而不显示多个,只需将 size 放入 select 它在桌面上看起来不错,但在移动设备上看起来不同但更好然后使用多个
【解决方案2】:

动态设置标签属性足以让所有 iOS 版本显示控件标签。原来这取决于 iOS 版本。

您没有在 iOS 7-9 上设置 innerText,但 iOS 10 及更高版本 需要设置 innerText 才能显示标签。

需要 iOS 10 及更高版本

    let option = document.createElement('option');
    option.label = option.innerText = 'option label';
    option.value = '123';

在 iOS 7-9 上不需要

var option = document.createElement('option');
option.label = 'option label';
option.value = '123';

【讨论】:

    猜你喜欢
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多