javascript - 将 css 更改为“selected=selected value”
问题描述
我正在使用 shopify 对电子商务的功能和 css 进行更改,并且我一直在尝试更改selected = selected
代码选项的 css。
名单:
这是代码:
HTML:
<select class="single-option-selector single-option-selector-{{ section.id }} product-form__input" id="SingleOptionSelector-{{ forloop.index0 }}" data-index="option{{ forloop.index }}">
{% for value in option.values %}
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected" class="selected-item"{% endif %} id="opcion-selector">{{ value }}</option>
{% endfor %}
</select>
CSS:
#SingleOptionSelector-0 {
margin-top: -5px;
display: inline-block;
height: 3em;
-webkit-appearance: none;
-moz-appearance: none;
font-family: 'ITC Souvenir Std';
background-color: #eef3eb;
overflow: hidden;
background: none;
}
#SingleOptionSelector-0 option {
color: #eb3439;
width: 2.5em;
float: left;
background-color: #eef3eb;
text-align: center;
font-size: 13px;
}
JS:
document.getElementById("SingleOptionSelector-0").size="3";
我试图通过内联属性:
<option value="{{ value | escape }}"{% if option.selected_value == value %} selected="selected" class="selected-item" style="color:red"{% endif %} id="opcion-selector">{{ value }}</option>
还有我selected
通过css在每个选项中创建的类selected-item
我什至尝试添加 JavaScript 样式和:checked
伪类。
我想不出任何其他方法来做到这一点,我被困住了。
任何想法?
解决方案
:checked 伪类最初适用于具有 HTML4 selected 和 checked 属性的元素
option:checked { display:none; }
<select>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
推荐阅读
- perl - 动态增加 Text::TabularDisplay 中的列大小
- node.js - Unable to access response object data outside the function in node js
- postgresql - 使用 Postgres 创建多个脚本的问题
- excel - VBA 到 GAS 脚本转换
- erlang - 如何通过 Elixir / Erlang 中的指针相等比较两个结构
- node.js - Winston 没有为我的 Heroku MERN 应用程序编写日志,尽管它在本地运行良好
- r - 如何连接到安装了防火墙的闪亮应用程序?
- java - 如何在展开地图中删除标记?
- python - 覆盖文件;更改内容但保留文件名
- android - 如何在 Xamarin 表单中创建带圆角/边缘的进度条