【问题标题】:Can't set attribute size="" in liquid-html element无法在 Liquid-html 元素中设置属性 size=""
【发布时间】:2019-08-29 13:47:57
【问题描述】:

我将动态项目传递给一个选择>选项,以使列表可以与项目一起选择,并且我想显示该“列表”内联(不带下拉菜单),为此我做了接下来的事情:

这是我的液体代码

<select class="pattern-select single-option-selector single-option-selector-{{ section.id }} product-form__input" id="SingleOptionSelector-{{ section.id }}-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
  {% for value in option.values %}
      <option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected"{% endif %}>{{ value }}</option>
  {% endfor %}
</select>   

这是我正在使用的 css

.pattern-select {
    display: inline-block;
    height: 3em;    
    -webkit-appearance: none;
    -moz-appearance: none;
}

.pattern-select option{
    display: inline-block;
    width: 2.5em;
    height: 2.5em;
    float:left;
}

我只需要在&lt;select... 中添加size="3" 作为属性以结束该功能,但是当我手动输入时,size="3" 未处理,就好像该属性尚未设置,因此我无法内联显示 select>option 结构。

这是我的 html 输出的样子:

<select class="pattern-select single-option-selector single-option-selector-product-template product-form__input" id="SingleOptionSelector-0" data-index="option1">
   <option value="S" selected="selected">S</option>
   <option value="M">M</option>
   <option value="L">L</option>
   <option value="XL">XL</option>
</select>

有什么建议吗?

干杯!

【问题讨论】:

  • 你试过内联css吗?
  • 嗨@RodenerDajes,是的,我就是这样写size="3"
  • 你能指定你是否使用npm包“液体”,它的版本。以及 node 和 npm 的版本?
  • 好吧,我终于找到了一种基本但实用的方法来实现它。谢谢大家

标签: javascript html sass liquid


【解决方案1】:

最后因为我不能再扩展这个问题,我得到了&lt;select&gt; id 并通过 javascript 传递它的属性大小本身:

document.getElementById("SingleOptionSelector-0").size = "3";

【讨论】:

    猜你喜欢
    • 2010-12-05
    • 1970-01-01
    • 2016-04-30
    • 2020-10-12
    • 2013-11-26
    • 2010-09-25
    • 1970-01-01
    • 2019-08-19
    • 2020-03-19
    相关资源
    最近更新 更多