$(document).ready(function(){
$(".menua1").click(function(){
//执行了点击事件的内容
});
});
function toggleMenu(){
var fs = window.top.document.getElementById("bframeset");
if(条件true){
$(".menua1_noclick").attr("class","menua1");
}else{
$(".menua1").attr("class","menua1_noclick");
}
}
//HTML
<a class="menua1">A按钮</a>
When I click the B button and call toggleMenu(), the class value of the element is changed. I think the click event in ready() should be invalid. When I call toggleMenu(), I change the class value to the initial value. value, click() should be able to run normally;
But no matter how the class value of the a tag is changed, it will not affect my original click. If the class value is changed, I can still click to enter and execute the jqeury code, solve it.
My purpose is to disable the original click event of button A after clicking button B, and enable the original click event of button A when button B is clicked again.
Waiting online, please give advice.
When I clicked button B and called toggleMenu() to change the class value of the element, I felt that the click event in ready() should be invalid
First of all, this understanding is wrong.
Give me an example:
There was a man named Xiao Ming. His parents called him Xiao Mingming, and his wife called him Da Mingming. One day, Xiao Ming’s hand was broken.
His parents saw it and asked:
Xiao Mingming, how did you break your hand? ?
His wife said:
Da Mingming accidentally cut it while cooking
He turned around and asked Xiao Ming:
Husband, do your hands still hurt?
Dad/Mom said:
Hey, they are so big Why do you still call me Da Mingming when you are dead? It doesn’t sound good
My wife said:
Okay, I won’t call you Da Mingming anymore
Question: Is Xiao Ming’s hand broken?
jQuery’s selector is used to select elements through different means,
but the
shanghai
you cause to it will not be eliminated just because you change one of its attributes.So back to the topic, the click event is bound to the element and needs to be cleared
The examples mentioned above are also interesting. To put it simply, the binding of events is only related to the element itself, and has little to do with its name in the future. It's like saying that your ID card represents you as a person, and then one day you change your name, does the ID card represent someone else? That’s the truth
$(".menua1").off('click'), wouldn't it be enough to unbind the click event of the button