ClientID

以下是代码片段:
  -----
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<script language="javascript">
function test()
{
//javascript获取不到对象,服务器端控件加上.ClientID起到唯一标识的作用,这样就找到了对象.
var PanDCount = document.getElementById("<%=txtPanDCount.ClientID%>").value;
var PanDScore = document.getElementById("<%=txtPanDScore.ClientID%>").value;
var DanXCount = document.getElementById("<%=txtDanXCount.ClientID%>").value;
var DanXScore = document.getElementById("<%=txtDanXScore.ClientID%>").value;
var DuoXCount = document.getElementById("<%=txtDuoXCount.ClientID%>").value;
var DuoXScore = document.getElementById("<%=txtDuoXScore.ClientID%>").value;
//强制类型转换
document.getElementById("<%=txtTotalScore.ClientID%>").value =
Number(PanDCount)*Number(PanDScore)
+ Number(DanXCount)*Number(DanXScore)
+ Number(DuoXCount)*Number(DuoXScore);
}
</script>
... ...

<input id="txtPanDCount" runat="server" class="input_2" type="text" onkeydown="test()" onkeyup="test()"/>题
<input id="txtDanXCount" type="text" class="input_2" runat="server" onkeydown="test()" onkeyup="test()"/>题
<input id="txtDuoXCount" type="text" class="input_2" runat="server" onkeydown="test()" onkeyup="test()"/>题
<input id="txtPanDScore" runat="server" class="input_2" type="text" onkeydown="test()" onkeyup="test()"/>分/题
<input id="txtDuoXScore" runat="server" class="input_2" type="text" onkeydown="test()" onkeyup="test()"/>分/题
<input id="txtDanXDScore" runat="server" class="input_2" type="text" onkeydown="test()" onkeyup="test()"/>分/题
<input id="txtTotalScore" runat="server" class="input_1" type="text" style=" 70px" />分
原文地址:https://www.cnblogs.com/Caesar/p/1016643.html