后台添加 Fix.Attributes.Add("onclick", "fix()");
前台JS出现的问题及解决办法:
1.aspx 页面的 fix() 和 另一个函数都写在 同一个 <script type="text/javascript" lanauage="javascript"></script>中。
此时不能调用,用alert('xx'); 都不能打印。
解决办法:将fix() 函数 单独放在一个<script type="text/javascript" lanauage="javascript"></script> 中。
2. 当<head > runat="server" 的时候,出现 <%=Fix.ClientID %> 报错。
function fix(){
var a = document.getElementById("<%=Fix.ClientID %>");
if (a.checked) {
document.getElementById("<%=spiDiscountPercent.ClientID %>").disabled = "disabled";
document.getElementById("<%=spiDiscountAmount.ClientID %>").disabled = "disabled"; //"disabled";
// alert(document.getElementById("<%=fixed_txt.ClientID %>").value);
}
else {
document.getElementById("<%=spiDiscountPercent.ClientID %>").disabled = "";
document.getElementById("<%=spiDiscountAmount.ClientID %>").disabled = ""; //"disabled";
}
}
解决办法:去掉head 中的runat='server'
3.第三个问题 没搞明白的。
有的页面用 document.getElementById("Fix") 能取到值。
有的不行,则只能用 document.getElementById("<%=Fix.ClientID %>")
搞不明白呢????