有太多与我相似的问题,以至于我遇到了很多错误的问题,而且我似乎无法判断我的问题是否重复。 我注册了一个帐户来问这个。
我的问题是代码给我“Uncaught SyntaxError: Unexpected token”
HTML
<section class="shopBoxBot" href="index.html">
<img class="shopImg" src=Images/Shop/Amethyst_Bracelet.jpg>
<p> hi </p>
</section>
Javascript
var shopSizer = document.querySelectorAll(".shopImg");
for (var i = 0; i < shopSizer.length; i++){
if (shopSizer[i].width => shopSizer[i].height){
shopSizer[i].style.height='100%';
}
else{ shopSizer[i].style.width='100%';
}
}
我想要的只是比较并查看哪个较大,高度或宽度,然后根据该决定将哪个作为父级的尺寸。
错误发生在这一行
if (shopSizer[i].width => shopSizer[i].height){
最佳答案
您错误地使用了比较运算符。 =>
应该是 >=
if (shopSizer[i].width => shopSizer[i].height){
应该是
if (shopSizer[i].width >= shopSizer[i].height){
关于javascript - 将 html 类的属性与 javascript 进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41073520/