【问题标题】:How to change select option text如何更改选择选项文本
【发布时间】:2023-01-09 15:03:21
【问题描述】:

当我为 select 标签设置 has-empty-data=true 属性时,列表选项中会添加一个空选项。那么如何为这个空选项标签设置文本呢?

<select name="address[province]" title="{{ 'customer.addresses.province' | t }}" has-empty-data="true" data-default="{{ form.province }}" id="provinceExist"></select>

我试过这样做但还是不行

document.getElementsByName('provinceExist').options[0].innerHTML = "Water";

【问题讨论】:

  • 你是getElementByName,参数是id,对吗?

标签: javascript


【解决方案1】:

您需要使用 getElementById 而不是 getElementByName,因为您的字段 ID 名为 provinceExist

document.getElementsById('provinceExist').options[0].innerHTML = "Water";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-08
    • 2022-01-18
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    相关资源
    最近更新 更多