jQuery.one()関数またはjQuery.off( )を使用できます
ここでの最善の解決策は、jQuery.off('click')
$("img").click(function(){
$("img").off('click');
});
次に、アラートがトリガーされたときに再度有効にします
例: http://jsfiddle.net/c7puz/
JS
// function to do something when the click is trigger
function enableSelect(){
$("img").click(function(){
$(this).toggleClass("hover");
// toggle off the click, so only first one will work,
// until the function is called again
$("img").off('click');
});
}enableSelect();
$("#btn").click(function(){
var pos = $("img.hover").parent().index();
if(pos > -1){
// tell us the selected image to work with
alert('The selected image is at position: ' + pos );
// clear the hover state
$("img").removeClass("hover");
// and enable the click again
enableSelect();
} else {
alert('no image selected');
}
});
幸運を ;-)