开发者

jquery: append button in cell

How i can insert a button in cell of table using jquery and process onclick event for 开发者_如何转开发that button?

Thank you.


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

http://jsfiddle.net/Fxayf/1/


<script>
    function insert(button){
        $(button).appendTo($('td.toinsert'));
    }
</script>
<table>
    <tr>
    <td class="toinsert">inside cell</td>
    </tr>
</table>
<input type="button" onclick="insert(this)" value="button"/>

Also for creating button and adding event to it

<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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜