jquery:单元格中的追加按钮

jquery:单元格中的追加按钮,jquery,Jquery,如何使用jquery在表的单元格中插入一个按钮,并为该按钮处理onclick事件 谢谢。var按钮=$(“你好”); var button = $("<button>Hi there</button>"); button.click(function() { alert("Hi back!"); }); button.appendTo("#tablecell"); 按钮。单击(函数(){ 警惕(“嗨,回来!”); }); 按钮。附加到(“#表格单元格”);

如何使用jquery在表的单元格中插入一个按钮,并为该按钮处理onclick事件

谢谢。

var按钮=$(“你好”);
var button = $("<button>Hi there</button>");
button.click(function() {
    alert("Hi back!");
});
button.appendTo("#tablecell");
按钮。单击(函数(){ 警惕(“嗨,回来!”); }); 按钮。附加到(“#表格单元格”);


功能插入(按钮){
$(按钮).appendTo($('td.toinsert'));
}
细胞内
还用于创建按钮和向其添加事件

<script>
    $(function(){
        $('<input></input>').attr({'type': 'button'}).val("button").click(function(){
            alert('hello');
        }).appendTo($('td.toinsert'));
    });
</script>
<table>
    <tr>
    <td class="toinsert">inside cell</td>
    </tr>
</table>

$(函数(){
$('').attr({'type':'button'}).val(“button”)。单击(函数(){
警惕(“你好”);
})。附件($('td.toinsert'));
});
细胞内
<script>
    $(function(){
        $('<input></input>').attr({'type': 'button'}).val("button").click(function(){
            alert('hello');
        }).appendTo($('td.toinsert'));
    });
</script>
<table>
    <tr>
    <td class="toinsert">inside cell</td>
    </tr>
</table>