如何在 jquery 1.9 中使用 .toggle [英] how to use .toggle with jquery 1.9
问题描述
我正在尝试在 jquery 1.9 中使用切换方法,但它已被删除,这是一个切换 div 内容的简单示例http://jsfiddle.net/Y5pFe/1/代码:
$(document).ready(function(e) {$('.divone').toggle(function() {$(this).text("点击一个");}, 功能() {$(this).text("点击两个");});});
请问有什么替代方法?
我只想使用 .click
并分配一个属性作为标志:
$(document).ready(function(e) {$('.divone').click(function() {if($(this).hasClass("点击")) {$(this).text("移除点击");$(this).removeClass("点击");} 别的 {$(this).text("添加点击");$(this).addClass("点击");}});});
i'm trying to use the toggle method with jquery 1.9 but it's been removed and here's a simple example to toggle div content http://jsfiddle.net/Y5pFe/1/ code :
<div class="divone"></div>
$(document).ready(function(e) {
$('.divone').toggle(function() {
$(this).text("click one");
}, function() {
$(this).text("click two");
});
});
what's the alternative method please ?
I would just use .click
and assign an attribute as a flag:
<div class="divone"></div>
$(document).ready(function(e) {
$('.divone').click(function() {
if($(this).hasClass("clicked")) {
$(this).text("removing click");
$(this).removeClass("clicked");
} else {
$(this).text("adding click");
$(this).addClass("clicked");
}
});
});
这篇关于如何在 jquery 1.9 中使用 .toggle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!