简体   繁体   中英

how to use guid with jquery in asp.net mvc 3 razor/jquery?

How can i create a id as a newguid for a button and use it in my jquery script? Something like:

   @{ 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>
@{ var id = Guid.NewGuid().ToString(); }
<input type="button" id="@id" name="Go" />

and the script:

<script type="text/javascript">
    $('#@(id)').click(function() { 
        alert('Thank you for clicking on button with id = ' + this.id);
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM