简体   繁体   English

通过 javascript 更改图像源似乎不起作用。 我究竟做错了什么?

[英]Change image source through javascript does not seem to work. What am I doing wrong?

I'm trying to change the current logo of this website: https://moonstrategy.io/about/ from我正在尝试更改此网站的当前徽标: https://moonstrategy.io/about/ from

https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_light_final.svg to https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_light_final.svg to https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg

I'm embedding this code in the webpage:我将此代码嵌入网页中:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>document.getElementByClassName(".tgp-exclude small").src="https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg";</script>

I've also tried using different class names and while I'm pretty sure I tried all of them, I can either not seem to find the right one, or I am totally off with the code.我也尝试过使用不同的 class 名称,虽然我很确定我尝试了所有这些名称,但我似乎找不到合适的名称,或者我完全不使用代码。

Help would be appreciated.帮助将不胜感激。

  1. You included jquery, but you don't use jquery您包括 jquery,但您不使用 jquery
  2. There is no such thing as getElementByClassName , there is getElementsByClassName没有getElementByClassName这样的东西,有getElementsByClassName
  3. getElementsByClassName returns NodeList and you want only one element, use querySelector instead. getElementsByClassName返回 NodeList 并且您只需要一个元素,请改用querySelector

nothing wrong here but I think the document.getElementsByClassName() returns an array of elements with the specified class name So it should be something like这里没有错,但我认为 document.getElementsByClassName() 返回具有指定 class 名称的元素数组所以它应该类似于

document.getElementsByClassName(".tgp-excludesmall")[0].src="https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg"; document.getElementsByClassName(".tgp-excludesmall")[0].src="https://moonstrategy.io/wp-content/uploads/2022/08/Moonstrategy_logo_vector_main_final.svg";

暂无
暂无

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

相关问题 将obj-c类传递给javascript不起作用。 我究竟做错了什么? - Passing obj-c class to javascript doesn't work. What am I doing wrong? JSF 2.2表单上的tagmanager.js不起作用。 我究竟做错了什么? - tagmanager.js on JSF 2.2 form doesn't work. What am I doing wrong? 在一条线上推动和取消移动是行不通的。 我究竟做错了什么? - pushing and unshifting in one line doesn't work. what am i doing wrong? 在 Node.js 上使用 Proxy.apply() 不起作用。 这是一个错误还是我做错了? - Using Proxy.apply() on Node.js does not work. Is this a bug or am I doing it wrong? jQuery代码有效,javascript不起作用,我在做什么错? - Jquery code works, javascript does not, what am i doing wrong? 我尝试了serialize()但似乎没有用? 我究竟做错了什么? - I tried serialize() but doesnt seem to work ? what am I doing wrong? if/else 语句似乎在 Javascript 中不起作用,我不知道我做错了什么 - If/else statements just do not seem to be working in Javascript and i don't know what I am doing wrong 删除节点时,pruneRoots 函数在下面的树算法中返回 undefined。 无法让它工作。 我究竟做错了什么? - pruneRoots function returning undefined in the below tree algorithm when removing a node. Unable to make it work. What am I doing wrong? 为什么这两个javascript函数似乎不相处...我在做什么错? - Why is it these two javascript functions seem to not be getting along…what am I doing wrong? 我正在猜测数字项目,但我的 if else 似乎无法正常工作。 我究竟做错了什么? - im doing a guess the number project but my if else doesn't seem to work properly. what am i doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM