连续 Unbind/Bind 点击
Sequential Unbind/Bind Click
我有 5 个 div 类 (button1, button2, button3, button4, button5)
我想要的是所有 类 都不可点击 onload(button1 除外),然后在点击 button1 后,button2 处于活动状态,其他按钮不活动,依此类推。
所以按顺序点击。
HTML
<map name="Map" id="Map">
<area id="button" title="HAT" alt="HAT" href="#" shape="poly" coords="xxx,xxx" />
<area id="button2" title="SUN CREAM" alt="SUN CREAM" href="#" shape="poly" coords="xxx,xxx" />
</map>
我试过了:
$(function(){ $("#button2").unbind("click"); });
作为初始函数,然后在button1下点击函数:
$("#button1").click(function() {
$("#Map #button2").bind("click");
});
这是因为它不允许点击 button2,但即使点击了 button1 仍然无法点击。
有什么想法吗?
你必须这样做 Document
$(document).ready(function(){
$(".btn").unbind("click",function(){
alert("unbind click");
});
});
function btnClick(thisObj){
//unbind all not current
$(".btn").not(thisObj).unbind("click");
//bind next btn
$(thisObj).next().bind("click",function(){
alert("bind click");
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" class="btn" name="btn1" value="1" onclick="btnClick(this);">
<input type="button" class="btn" name="btn2" value="2" onclick="btnClick(this);">
<input type="button" class="btn" name="btn3" value="3" onclick="btnClick(this);">
<input type="button" class="btn" name="btn4" value="4" onclick="btnClick(this);">
<input type="button" class="btn" name="btn5" value="5" onclick="btnClick(this);">
试试这个:您可以禁用单击按钮并启用下一步按钮,请参见下面的代码
$(document).ready(function(){
$('#Map').find('area').not('#button').attr('disabled',true);
$('#Map area').on("click",function(){
$(this).attr('disabled',true);
$(this).next('area').removeAttr('disabled');
});
});
在更通用和建设性的方法中,实施 jQuery 插件:
$("#button1").sequence("click")
.handle(function () {
alert("YOU...")
})
.handleNext("#button2", function () {
alert("SHALL...")
})
.handleNext("#button3", function () {
if (prompt("NOT PASS!!!") != "I'm Frodo, drunkie!") {
alert("BZZZZZZZT!");
return this.runBackward();
}
alert("Ah, oh, okaay...");
})
.handleNext("#button4", function () {
alert("Pwned! ]:-}");
this.resetSequence();
});
$(function () {
$("#button1").sequence("click")
.handle(function () {
alert("YOU...")
})
.handleNext("#button2", function () {
alert("SHALL...")
})
.handleNext("#button3", function () {
if (prompt("NOT PASS!!!") != "I'm Frodo, drunkie!") {
alert("BZZZZZZZT!");
return this.runBackward();
}
alert("Ah, oh, okaay...");
})
.handleNext("#button4", function () {
alert("Pwned! ]:-}");
this.resetSequence();
});
});
(function ($) {
$.fn.sequence = function (event) {
this.sequencer = {
event: event,
plugged: this,
disable : function (element, enable) {
$(element).attr("disabled", (enable !== false) ? "disabled" : false);
},
disablePrev: function (enable) {
if (this.prevInSequence)
this.disable(this.prevInSequence, enable);
},
disableNext: function (enable) {
if (this.nextInSequence)
this.disable(this.nextInSequence, enable);
},
hasPrev : function (prev) {
this.prevInSequence = prev;
},
hasNext : function (next) {
this.nextInSequence = next;
this.plugged.resetSequence();
},
process : function (callback, event) {
this.disablePrev();
if (callback.call(this.plugged, event) === false)
return;
this.disable(this.plugged);
this.disableNext(false);
},
reset: function () {
this.disablePrev(false);
if (this.nextInSequence)
this.nextInSequence.sequencer.reset();
this.disable(this.plugged);
}
};
this.resetSequence = function () {
this.sequencer.disable(this, false);
this.sequencer.disableNext(this);
if (this.sequencer.prevInSequence)
this.sequencer.prevInSequence.resetSequence();
}
this.handle = function (callback) {
var self = this;
this.on(this.sequencer.event, function (e) {
if (self.attr("disabled"))
return;
self.sequencer.process.call(self.sequencer, callback, e);
});
return this;
}
this.handleNext = function (selector, callback) {
var next = $(selector);
var sequence = next.sequence(this.sequencer.event).handle(callback);
this.sequencer.hasNext(next);
sequence.sequencer.hasPrev(this);
return sequence;
}
this.runBackward = function () {
this.sequencer.reset();
return false;
}
return this;
}
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="button1">1</button>
<button id="button2">2</button>
<button id="button3">3</button>
<button id="button4">Finish</button>
我有 5 个 div 类 (button1, button2, button3, button4, button5)
我想要的是所有 类 都不可点击 onload(button1 除外),然后在点击 button1 后,button2 处于活动状态,其他按钮不活动,依此类推。
所以按顺序点击。
HTML
<map name="Map" id="Map">
<area id="button" title="HAT" alt="HAT" href="#" shape="poly" coords="xxx,xxx" />
<area id="button2" title="SUN CREAM" alt="SUN CREAM" href="#" shape="poly" coords="xxx,xxx" />
</map>
我试过了:
$(function(){ $("#button2").unbind("click"); });
作为初始函数,然后在button1下点击函数:
$("#button1").click(function() {
$("#Map #button2").bind("click");
});
这是因为它不允许点击 button2,但即使点击了 button1 仍然无法点击。
有什么想法吗?
你必须这样做 Document
$(document).ready(function(){
$(".btn").unbind("click",function(){
alert("unbind click");
});
});
function btnClick(thisObj){
//unbind all not current
$(".btn").not(thisObj).unbind("click");
//bind next btn
$(thisObj).next().bind("click",function(){
alert("bind click");
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" class="btn" name="btn1" value="1" onclick="btnClick(this);">
<input type="button" class="btn" name="btn2" value="2" onclick="btnClick(this);">
<input type="button" class="btn" name="btn3" value="3" onclick="btnClick(this);">
<input type="button" class="btn" name="btn4" value="4" onclick="btnClick(this);">
<input type="button" class="btn" name="btn5" value="5" onclick="btnClick(this);">
试试这个:您可以禁用单击按钮并启用下一步按钮,请参见下面的代码
$(document).ready(function(){
$('#Map').find('area').not('#button').attr('disabled',true);
$('#Map area').on("click",function(){
$(this).attr('disabled',true);
$(this).next('area').removeAttr('disabled');
});
});
在更通用和建设性的方法中,实施 jQuery 插件:
$("#button1").sequence("click")
.handle(function () {
alert("YOU...")
})
.handleNext("#button2", function () {
alert("SHALL...")
})
.handleNext("#button3", function () {
if (prompt("NOT PASS!!!") != "I'm Frodo, drunkie!") {
alert("BZZZZZZZT!");
return this.runBackward();
}
alert("Ah, oh, okaay...");
})
.handleNext("#button4", function () {
alert("Pwned! ]:-}");
this.resetSequence();
});
$(function () {
$("#button1").sequence("click")
.handle(function () {
alert("YOU...")
})
.handleNext("#button2", function () {
alert("SHALL...")
})
.handleNext("#button3", function () {
if (prompt("NOT PASS!!!") != "I'm Frodo, drunkie!") {
alert("BZZZZZZZT!");
return this.runBackward();
}
alert("Ah, oh, okaay...");
})
.handleNext("#button4", function () {
alert("Pwned! ]:-}");
this.resetSequence();
});
});
(function ($) {
$.fn.sequence = function (event) {
this.sequencer = {
event: event,
plugged: this,
disable : function (element, enable) {
$(element).attr("disabled", (enable !== false) ? "disabled" : false);
},
disablePrev: function (enable) {
if (this.prevInSequence)
this.disable(this.prevInSequence, enable);
},
disableNext: function (enable) {
if (this.nextInSequence)
this.disable(this.nextInSequence, enable);
},
hasPrev : function (prev) {
this.prevInSequence = prev;
},
hasNext : function (next) {
this.nextInSequence = next;
this.plugged.resetSequence();
},
process : function (callback, event) {
this.disablePrev();
if (callback.call(this.plugged, event) === false)
return;
this.disable(this.plugged);
this.disableNext(false);
},
reset: function () {
this.disablePrev(false);
if (this.nextInSequence)
this.nextInSequence.sequencer.reset();
this.disable(this.plugged);
}
};
this.resetSequence = function () {
this.sequencer.disable(this, false);
this.sequencer.disableNext(this);
if (this.sequencer.prevInSequence)
this.sequencer.prevInSequence.resetSequence();
}
this.handle = function (callback) {
var self = this;
this.on(this.sequencer.event, function (e) {
if (self.attr("disabled"))
return;
self.sequencer.process.call(self.sequencer, callback, e);
});
return this;
}
this.handleNext = function (selector, callback) {
var next = $(selector);
var sequence = next.sequence(this.sequencer.event).handle(callback);
this.sequencer.hasNext(next);
sequence.sequencer.hasPrev(this);
return sequence;
}
this.runBackward = function () {
this.sequencer.reset();
return false;
}
return this;
}
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button id="button1">1</button>
<button id="button2">2</button>
<button id="button3">3</button>
<button id="button4">Finish</button>