简体   繁体   English

不同计算器上的不同计算与我编写的一个

[英]Different calculation on different calculator vs. one I scripted

On clicking div click , div three background color should change and then change back after a second.单击 div click时,div three背景颜色应该会改变,然后在一秒钟后变回来。 I have the code below which adds the class but the style doesn't show on the page.我有下面的代码,它添加了 class 但样式未显示在页面上。

 let temp = document.querySelector('.three'); document.querySelector('.clickhere').addEventListener('click', () => { temp.classList.add('.select'); console.log(temp); setTimeout(function() { temp.classList.remove('.select'); console.log(temp); }, 1000); });
 .one { background-color: red; }.two { background-color: green; }.three { background-color: blue; }.select { background-color: black; }.clickhere { background-color: yellow; }
 <div class="one"> ONE </div> <div class="two"> TWO </div> <div class="three"> THREE </div> <div class="clickhere"> CLICK HERE </div>

Updated your snippet, I only had to replace .select with select更新了您的代码段,我只需.select替换为select

It's important to use period before the css classes only when selecting them with jQuery, when adding a new class and removing it, you should just write the name of it like you would inside the div tag.仅在使用 jQuery 选择 css 类之前使用句点很重要,当添加新的 class 并删除它时,您应该像在div中一样写下它的名称。

EDIT: I just saw that the question was already answered in the comments, credits to @maazadeeb: :)编辑:我刚刚看到评论中已经回答了这个问题,感谢@maazadeeb::)

 let temp = document.querySelector('.three'); document.querySelector('.clickhere').addEventListener('click', () => { temp.classList.add('select'); console.log(temp); setTimeout(function() { temp.classList.remove('select'); console.log(temp); }, 1000); });
 .one { background-color: red; }.two { background-color: green; }.three { background-color: blue; }.select { background-color: black;important. }:clickhere { background-color; yellow; }
 <div class="one"> ONE </div> <div class="two"> TWO </div> <div class="three"> THREE </div> <div class="clickhere"> CLICK HERE </div>

temp.classList.add(' .select '); temp.classList.add('. select '); should be update as temp.classList.add(' select ');应该更新为 temp.classList.add(' select ');

 let temp = document.querySelector('.three'); document.querySelector('.clickhere').addEventListener('click', () => { temp.classList.add('select'); setTimeout(function () { temp.classList.remove('select'); }, 1000); });
 .one { background-color: red; }.two { background-color: green; }.three { background-color: blue; }.select { background-color: black; }.clickhere { background-color: yellow; }.select { background: coral; }
 <div class="one"> ONE </div> <div class="two"> TWO </div> <div class="three"> THREE </div> <div class="clickhere"> CLICK HERE </div>

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

相关问题 相同的代码,不同的结果在Fiddle与VS - Same code, different results in Fiddle vs. VS 为什么在带有条件(三元)运算符的javascript中,“ =”与“ ===”会得到不同的结果? - Why do I get different results with “=” vs. “===” in javascript with Conditional (Ternary) Operators? 不同条件的 JQuery 计算器 - JQuery Calculator for Different Conditions JavaScript VS PHP:相同的计算返回不同的结果 - JavaScript VS PHP: The same calculation returns different result 使用类/构造方法与可变方法时的范围不同 - different scope when using class/constructor vs. variable methods 静态布局与jQuery wrapInner-不同的输出 - Static layout vs. jQuery wrapInner - different output $ regex匹配模式在MongoDB与Javascript中的结果不同 - $regex match pattern has different result in MongoDB vs. Javascript 为什么结果不同(使用var vs. let)? - Why is result different (using var vs. let)? 为什么 DuckDuckGo 搜索结果在浏览器上与使用请求时不同? - Why are DuckDuckGo search results different on the browser vs. using request? XMLHttpRequest对<input type =“button”>与<button>的不同行为 - Different Behavior of XMLHttpRequest for <input type=“button”> vs. <button>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM