<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="server">
</script>
<asp:Content ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript">
var globals = {};
globals.controlIdentities = {};
globals.controlIdentities.someControl1 = '<%= Button1.ClientID %>';
globals.controlIdentities.someControl2 = '<%= TextBox1.ClientID %>';
</script>
<script type="text/javascript" src="https://www.jb51.net/JScript.js"></script>
</asp:Content>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:TextBox runat="server"></asp:TextBox>
<asp:Button runat="server" Text="Button" />
<input type="button" value="button" />
</asp:Content>
JScript.js
复制代码 代码如下:
function ChangeText()
{
var btn=document.getElementById(globals.controlIdentities.someControl1);
btn.value="from extended js";
var txt=document.getElementById(globals.controlIdentities.someControl2);
btn.value="from extended js";
}
结束语:
在上面两种方法中,也没有真正的实现aspx和js的完全解耦,所以,在js文件中,最好还是加上:
///<reference path="Default5.aspx"/>