Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
按钮的JQuery附加函数_Jquery_Jquery Ui_Jquery Plugins - Fatal编程技术网

按钮的JQuery附加函数

按钮的JQuery附加函数,jquery,jquery-ui,jquery-plugins,Jquery,Jquery Ui,Jquery Plugins,我想使用jqueryappend函数在button.plz帮助之后追加一个按钮 var button = $("<button>Hi there</button>"); button.click(function() { alert("Hi back!"); }); button.appendTo("#tablecell"); var按钮=$(“你好”); 按钮。单击(函数(){ 警惕(“嗨,回来!”); }); 按钮。附加到(“#表格单元格”); 上面的代码

我想使用jqueryappend函数在button.plz帮助之后追加一个按钮

var button = $("<button>Hi there</button>");
button.click(function() {
    alert("Hi back!");
});
button.appendTo("#tablecell");
var按钮=$(“你好”);
按钮。单击(函数(){
警惕(“嗨,回来!”);
});
按钮。附加到(“#表格单元格”);
上面的代码用于在表中的某些文本后追加按钮。但我想在按钮后追加按钮

var button = $("<button>Hi there</button>");
$("#tablecell").on('click', button, function() {
    alert("Hi back!");
});
button.insertAfter("#tablecell");

为什么需要
.on()
委托 因为您的按钮,在页面加载后即DOM就绪后追加到DOM。所以普通的绑定在这里不起作用,您需要委托(aka,live)事件处理程序

$(target).on(eventName, handlerFunction) // for ordinary binding
但是

您还有另一个选项
.delegate()
,看起来:

$(container).delegate(target, eventName, handlerFunction);

+1表示。on()。当人们(和我)在DOM元素准备就绪之前将事件挂接在DOM元素上时,这会让人(和我)发疯。我给出了一个例如table的代码…我不需要在table之后插入它。关键是我在html中有一个按钮。。。更多现在我想在这个按钮后附加一个按钮…没有更多
$(container).on(eventName, target, handler) // for delegate binding
$(container).delegate(target, eventName, handlerFunction);