0
尊敬的女士们,先生们,Toggleclass几个div编号/班jQuery的+ jQuery的移动
我有对jQuery库的toggleclass功能一个豆蔻问题。我目前正在研究一个带有列表和内容文章的jquery-mobile应用程序。在这篇文章中我想实现一个“夜间模式”。每篇文章触摸夜间按钮后,与同一班,但!!不同的ID!应该切换其类。
我会告诉你我的文章html结构,我的CSS和我的jquery脚本。
所以这是我的代码结构:
$(document).ready(function(){
$('#nightmode_article1').click(function(){
$('#article1').toggleClass('night');
});
$('#nightmode_article2').click(function(){
$('#article2').toggleClass('night');
});
});
.day {
\t \t background-image: url(images/background.jpg);
\t background-repeat:repeat;
\t text-align: center;
}
.night {
\t background-image: url(images/background-night.jpg);
\t background-repeat:repeat;
\t text-align: center;
\t color: #F0F0F0;
\t text-shadow: none;
}
<div data-role="page" id="article1" class="day">
<header data-role="header">
<button id="nightmode_article1"><img src="images/night-icon.png" /></button>
<h1>Article1</h1>
</header>
<article data-role="content">
</article>
<footer data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul>
<li><a href="#" data-icon="home">Home</a></li>
<li><a href="#" data-icon="back">Test</a></li>
</ul>
</nav>
</footer>
</div>
<div data-role="page" id="article2" class="day">
<header data-role="header">
<button id="nightmode_article2"><img src="images/night-icon.png" /></button>
<h1>Article1</h1>
</header>
<article data-role="content">
</article>
<footer data-role="footer" data-position="fixed">
<nav data-role="navbar">
<ul>
<li><a href="#" data-icon="home">Home</a></li>
<li><a href="#" data-icon="back">Test</a></li>
</ul>
</nav>
</footer>
</div>
是否有可能不使不同的按钮为每篇文章?我想在每篇文章中切换课程(只有一篇文章ID),只需触摸/按一个按钮即可。
可能吗?
最好的问候和许多很多谢谢!
嘿,伙伴。非常感谢你。这有助于我很多,它的工作原理:-)所以它似乎最好的解决方案是最简单的,有时你只是不能看到它:-) – dimi 2014-10-28 20:50:16
更改ID到类的按钮和纠正语法解决了我的问题:-) – dimi 2014-10-28 20:50:47
@dimi,很高兴我能帮忙! – ezanker 2014-10-28 21:14:29