Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使附加仅在第一次发生_Javascript_Jquery - Fatal编程技术网

Javascript 使附加仅在第一次发生

Javascript 使附加仅在第一次发生,javascript,jquery,Javascript,Jquery,我的列表中有一个触发此事件的按钮: js: $(this).parents('tr') .find('.class') .append("<input type='text' size='5'/>"); $(this.parents('tr')) .find(“.class”) .附加(“”); 是否有可能在第一次发生这种附加 像一个返回false,不知道 谢谢 假设此行为发生在单击事件上,您可以使用。例如: 尝试使用该方法,而不是单击()。我看到了上

我的列表中有一个触发此事件的按钮:

js:

$(this).parents('tr')
       .find('.class')
       .append("<input type='text' size='5'/>");
$(this.parents('tr'))
.find(“.class”)
.附加(“”);
是否有可能在第一次发生这种附加

像一个
返回false
,不知道


谢谢

假设此行为发生在
单击事件上,您可以使用。例如:


尝试使用该方法,而不是单击()。

我看到了上一篇帖子:这就是你要找的吗?将尝试此方法,brb并显示结果。已更新
delegate
比live
更高效,所以希望这没问题。如果你真的需要
live
,我会再次更新:)我想用delagete,现在你告诉我,会用的!谢谢
$('#my-button').one('click', function(e) {
    e.preventDefault();
    $(this).parents('tr')
       .find('.class')
       .append("<input type='text' size='5'/>");
});
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);