我有一个关于如何在调用之后消除我的jQuery函数onclick的问题,它似乎无法工作但是在调用它之后,它必须是真的,所以它必须在函数中删除。非常感谢!
$(document).ready(function(){
$("#try-out").mouseenter(function(){
$("#try-out").fadeTo("fast",0.9);
});
$("#try-out").mouseleave(function(){
$("#try-out").fadeTo("fast", 0.7);
});
var onclick = function(){
$("#try-out").click(function(){
$(".button-text").fadeOut(function() {
$(this).text("Downloading... Your account wil be set up whitin seconds!").css(
{"font-family": "biko",
"color": "grey",
"text-decoration": "none",
"padding-top": "3%"}).fadeIn("slow");}
);
});
}
onclick();
if (onclick){
delete onclick;
}
});
答案 0 :(得分:5)
使用jquery one方法,这将只有一次点击有效:
$("#try-out").one('click', function(){
$(".button-text").fadeOut(function() {
$(this).text("Downloading... Your account wil be set up whitin seconds!").css(
{"font-family": "biko",
"color": "grey",
"text-decoration": "none",
"padding-top": "3%"}).fadeIn("slow");}
);
});
答案 1 :(得分:1)
使用one只为元素注册一次click事件。
$("#try-out").one('click', function(){
$(".button-text").fadeOut(function() {
$(this).text("Downloading... Your account wil be set up whitin seconds!").css(
{"font-family": "biko",
"color": "grey",
"text-decoration": "none",
"padding-top": "3%"}).fadeIn("slow");}
);
});
删除您编写的onclick
函数。
$(document).ready(function(){
$("#try-out").mouseenter(function(){
$("#try-out").fadeTo("fast",0.9);
});
$("#try-out").mouseleave(function(){
$("#try-out").fadeTo("fast", 0.7);
});
$("#try-out").one('click' ,function(){
$(".button-text").fadeOut(function() {
$(this).text("Downloading... Your account wil be set up whitin seconds!").css(
{"font-family": "biko",
"color": "grey",
"text-decoration": "none",
"padding-top": "3%"}).fadeIn("slow");}
);
});
});