如何创建一个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>
答案 0 :(得分: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>