开发者

jquery: append button in cell

开发者 https://www.devze.com 2023-02-12 22:14 出处:网络
How i can insert a button in cell of table using jquery and process onclick event for 开发者_如何转开发that button?

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

精彩评论

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