这应该工作,还是我做错了什么?
HTML:
<div class="header-title">
<h1 class="h1-title" id='title'>America</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$('#title').click(function(){
var classExist = $(this).hasClass('active-t');
if(classExist = false) {
$('.header-title').html("<h1 class='h1-title'>'Murica!</h1>");
}
if(classExist = true) {
$('.header-title').html("<h1 class='h1-title'>America</h1>");
}
});
Run Code Online (Sandbox Code Playgroud)
无论如何,我不能让它工作
你可以简单:
$('#title').click(function() {
$(this).hasClass('active-t') ? $('.header-title').html("<h1 class='h1-title'>America</h1>") : $('.header-title').html("<h1 class='h1-title'>'Murica!</h1>");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
140 次 |
| 最近记录: |