【发布时间】:2019-05-01 09:20:41
【问题描述】:
我试图在单击时更改按钮的类,以便在下次单击时执行不同的操作。 (我不想使用切换)
更改类后,下次单击这些按钮时,即使类已更改,也不会发生任何事情。谁能帮帮我?我刚开始接触jQuery,所以我不知道很多高级机制。
$(".showcontactbutton").click(function(){
$("#contactform").show();
//$(this).attr('class', 'hidecontactbutton');
$(this).removeClass('showcontactbutton').addClass('hidecontactbutton');
$(this).text("Hide Contact Form");
//html("<button id='hidecontactbutton'>Hide Contact Form</button>");
});
$(".hidecontactbutton").click(function(){
alert("Works:");
$("#contactform").hide();
//$(this).attr('id', 'showcontactbutton');
$(this).removeClass('hidecontactbutton').addClass('showcontactbutton');
$(this).text("Contact Us");
});
【问题讨论】: