2009-10-15 29 views
0

在ASP.net vs 05 C#上工作,有三個textBox.Length,Height,Sft.I要乘以長度*高度並希望將值放在Sft文本上。如何使用JavaScript在文本框中乘和設置乘積值

<asp:TextBox ID="txtLength" runat="server"></asp:TextBox> 
       <asp:TextBox ID="txtHeight" runat="server" onblar="javascript:ComputeSft();" ></asp:TextBox> 
       <asp:TextBox ID="txtSft" runat="server"></asp:TextBox></td> 



Sft=Length*Height. 

function ComputeSft() 
{ 
    var _nLength, _nHeight,_nSft; 
    _nLength=document.getElementById("txtLength").innerText; 
    _nHeight=document.getElementById("txtHeight").innerText; 
    _nSft=_nLength*_nHeight; 
    alert(_nSft); 
    txtSft.Text=_nSft; 
} 

如何乘?以及如何設置文本框的乘法值?

回答

0

你寫的代碼是一個JavaScript代碼中沒有innerText JavaScript中使用值,而不是

var txtSft=document.getElementById('<id of sfttext>'); 
txtSft.value=_nSft; 
2

我相信你正在尋找的是value財產。

試試這個:

function ComputeSft() 
{ 
    var _nLength = document.getElementById("txtLength").value; 
    var _nHeight = document.getElementById("txtHeight").value; 
    var _nSft = _nLength * _nHeight; 
    alert(_nSft); 
    document.getElementById("txtSft").value = _nSft; 
}