如何在javascript中翻转布尔变量的值,而不必两次包含变量名?所以
foobarthings[foothing][barthing] = !foobarthings[foothing][barthing];
Run Code Online (Sandbox Code Playgroud)
没有写foobarthings[foothing][barthing]两次.
我见过类似的问题,例如“如何在纯 JavaScript 中切换元素的类? ”,但这个问题指的是属性。
我有一个像这样的复选框:
<span class="newsletter-checkbox">
<input type="checkbox" name="newsletter" id="newsletter" checked> Sign up to the newsletter as well - recieve new posts in your inbox
</span>Run Code Online (Sandbox Code Playgroud)
如何做到这样,当.newsletter-checkbox单击其中的任何位置(包括文本)时,它会切换复选框checked属性?