0

如何创建一个 id 作为按钮的 newguid 并在我的 jquery 脚本中使用它?就像是:

   @{ var id = Guid.NewGuid().ToString(); } //

<input type=button id="@id" name="Go" /> @*how can i use this newguid as an id for my button?*@

<script>
            @*how can i use this id to attach an eventhandler to for my button?*@
            $("@id ).click(function(){ 
            });
</script>
4

1 回答 1

3
@{ var id = Guid.NewGuid().ToString(); }
<input type="button" id="@id" name="Go" />

和脚本:

<script type="text/javascript">
    $('#@(id)').click(function() { 
        alert('Thank you for clicking on button with id = ' + this.id);
    });
</script>
于 2012-06-21T07:11:54.793 回答