类上的Javascript更改值
以下是html:类上的Javascript更改值,javascript,html,Javascript,Html,以下是html: <a class="nsg-form--drop-down--label nsg-grad--light-grey nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown" style="" title="" tabindex="0"> <span class
<a class="nsg-form--drop-down--label nsg-grad--light-grey nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown" style="" title="" tabindex="0">
<span class="js-selectBox-label">SIZE </span>
<span class="js-selectBox-value nsg-form--drop-down--selected-option"> </span>
</a>
由于某种原因,我无法更改该值。这是实际更改值时的外观
<a class="nsg-form--drop-down--label nsg-grad--light-grey nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown" style="" title="" tabindex="0">
<span class="js-selectBox-label">SIZE </span>
<span class="js-selectBox-value nsg-form--drop-down--selected-option">(US 8)</span>
</a>
大小
(美国8)
感谢您的帮助。文档。GetElementsByCassName返回一个htmlcollection。您需要获取索引才能更改其中的文本
document.getElementsByClassName(“js-selectBox-value-nsg-form--drop-down--selected-option”)[0]。innerHTML='(US 8)
大小
您应该更好地描述您期望的结果。您试图针对哪些元素?a元素和span元素都没有值属性(IIRC),因此您可能希望使用innerText。@JackBashford,啊,我将尝试innerText
<a class="nsg-form--drop-down--label nsg-grad--light-grey nsg-form--drop-down exp-pdp-size-dropdown exp-pdp-dropdown two-column-dropdown selectBox-dropdown" style="" title="" tabindex="0">
<span class="js-selectBox-label">SIZE </span>
<span class="js-selectBox-value nsg-form--drop-down--selected-option">(US 8)</span>
</a>