简体   繁体   English

在asp.net mvc 3 razor / jquery中,如何在jQuery中使用guid?

[英]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? 我如何创建一个id作为按钮的newguid并在我的jquery脚本中使用它? 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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