我现在有点困惑。让我解释:
我见过人们谈论在 asp.net (3.5) 中向页面添加按钮或其他控件,当控件呈现时,它会更改该控件的 Id,例如。Button1 变成 Button1_somethingsomething 阻止他们使用 jQuery,他们最终使用的是诸如<%controlId.ClientId %>
所以我做了一个小测试
1. I added a button on the page:
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<div>
2. Then I added a JavaScript and jQuery:
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
alert("Hello world!");
});
});
</script>
3. The generated html is this:
<div>
<input type="submit" name="Button1" value="Button" id="Button1" />
<div>
现在,我没有看到 ASP.NET (asp.net 3.5) 更改了 ID。为什么我会看到不同的行为?
顺便提一句。当我按下按钮时,这确实有效!
谢谢。