没有$到价格架构内容属性的附加价格

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了没有$到价格架构内容属性的附加价格相关的知识,希望对你有一定的参考价值。

我试图将:<p class="regular-price">$7.07</p>的7.07(目前没有符号)附加到这里的内容属性:<meta itemprop="price" content="7.07 Here" />

答案

以下代码应该实现您对vanilla javascript的期望:

(function () {
  // Get references to the two elements
  var metaElement = document.querySelector('meta');
  var priceElement = document.querySelector('.regular-price');

  // Get the value of the `regular-price` element and remove the $ sign
  var priceValueModified = priceElement.innerhtml.replace('$', '');

  // Set the modified value as the attribute of the meta element
  metaElement.setAttribute('content', priceValueModified);
})();
<meta itemprop="price" content="" />
<p class="regular-price">$7.07</p>

以上是关于没有$到价格架构内容属性的附加价格的主要内容,如果未能解决你的问题,请参考以下文章