更改<option = class>之间的文本...

时间:2017-01-12 10:55:55

标签: html css html-select

我有这段代码:

&#13;
&#13;
<select class="cc-product-variant-selectbox j-product__variants" data-action="changeVariant">
  <option class="j-product__variants__item" value="0" data-params="{&quot;price&quot;:158,&quot;priceFormatted&quot;:&quot;158,00 \u20ac&quot;,&quot;oldPriceFormatted&quot;:&quot;0,00 \u20ac&quot;,&quot;basicPrice&quot;:0,&quot;basicPriceFormatted&quot;:&quot;0,00 \u20ac&quot;,&quot;basicPriceUnit&quot;:&quot;&amp;nbsp;&quot;,&quot;oldPrice&quot;:0,&quot;availability&quot;:1,&quot;availabilityText&quot;:&quot;disponibile&quot;,&quot;delivery&quot;:2,&quot;pool&quot;:&quot;Infinity&quot;,&quot;weightFormatted&quot;:&quot;0,1 kg&quot;,&quot;weight&quot;:0.1}"
          title="1 metro     158,00 €" content="1 metro" selected="selected">
    1 metro 158,00 €</option>
&#13;
&#13;
&#13;

我会更改Dropbox文字&#34; 1 metro 158,00€&#34; (即<option>..</option>之间)&#34; 1地铁&#34;所以没有价格。我在css中尝试了这段代码:

.j-product__variants__item"{content:"1 metro";}

但它不起作用。 我该如何解决?

1 个答案:

答案 0 :(得分:0)

快速而肮脏的Javascript解决方案:

// document.querySelectorAll('.j-product__variants__item')[0].innerHTML = document.querySelectorAll('.j-product__variants__item')[0].textContent.replace('158,00 €','');
<body onload="document.querySelectorAll('.j-product__variants__item')[0].innerHTML = document.querySelectorAll('.j-product__variants__item')[0].textContent.replace('158,00 €','');">
  <select class="cc-product-variant-selectbox j-product__variants" data-action="changeVariant">
    <option class="j-product__variants__item" value="0" data-params="{&quot;price&quot;:158,&quot;priceFormatted&quot;:&quot;158,00 \u20ac&quot;,&quot;oldPriceFormatted&quot;:&quot;0,00 \u20ac&quot;,&quot;basicPrice&quot;:0,&quot;basicPriceFormatted&quot;:&quot;0,00 \u20ac&quot;,&quot;basicPriceUnit&quot;:&quot;&amp;nbsp;&quot;,&quot;oldPrice&quot;:0,&quot;availability&quot;:1,&quot;availabilityText&quot;:&quot;disponibile&quot;,&quot;delivery&quot;:2,&quot;pool&quot;:&quot;Infinity&quot;,&quot;weightFormatted&quot;:&quot;0,1 kg&quot;,&quot;weight&quot;:0.1}"
    title="1 metro     158,00 €" content="1 metro" selected="selected">
      1 metro 158,00 €</option>
  </select>
</body>