如何实现在客户端动态改一个textbox的值,显示另两个textbox里的数字相加的值,decimal类型
想在另两个textbox的onblur事件里实现.
------解决方案--------------------------------------------------------
- HTML code
<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title> <script type="text/javascript"> function calc() { if(document.getElementById("TextBox1").value != "" && document.getElementById("TextBox2").value != "") document.getElementById("TextBox3").value = parseFloat(document.getElementById("TextBox1").value) + parseFloat(document.getElementById("TextBox2").value); } </script></head><body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" onblur="calc()"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" onblur="calc()"></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> </div> </form></body></html>
------解决方案--------------------------------------------------------
用js脚本,在ONBLUR事件中,将需要求和的两个textbox中的值转换为数字类型,在进行相加
将加的结果赋给textbox就可以了