i have on a list a button that fire this event:
js:
$(this).parents('tr')
.find('.class')
.append("<input type='text' size='5'/>");
its possible to开发者_StackOverflow社区 make this append happen just in the first time?
like a return false
, dont know.
Thanks!
Assuming that this behavior is happening on a click
event, you can use one. E.g.,
$('#my-button').one('click', function(e) {
e.preventDefault();
$(this).parents('tr')
.find('.class')
.append("<input type='text' size='5'/>");
});
Edit: using
delegate
:
var selector = '#my-button',
handler = function(e) {
// prevent default behavior
e.preventDefault();
// make sure this only runs once
$(document).undelegate(selector, 'click', handler);
// actual behavior
$(this).parents('tr')
.find('.class')
.append("<input type='text' size='5'/>");
};
$(document).delegate(selector, 'click', handler);
try the one() method instead of click().
精彩评论