简体   繁体   English

我想弄清楚这里出了什么问题

[英]I am trying to figure out what is wrong here

I am writing some code and I keep getting the error of "document.getElementsByClassName".我正在编写一些代码,但我不断收到“document.getElementsByClassName”的错误。 Here is my code.这是我的代码。 What could be wrong?`有什么问题吗?

$("#pre-order").change(function(){   updateDisplay();})
function updateDisplay(){
 var preo = document.getElementsByClassName('product-single__meta');
 preo.addClass('preorder');
 }
 updateDisplay();

Why are you combining jquery with regular javascript.为什么要将 jquery 与常规 javascript 结合使用。 you could do你可以做

var preo = $('.product-single__meta');

or even better.甚至更好。 one liner一个班轮

$('.product-single__meta').addClass('preOrder');

That does add the class but when the id of pre-order is not present I don't need the preorder class.这确实添加了 class,但是当预购的 id 不存在时,我不需要预购 class。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM