Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript添加两个文本框值并显示在第三个文本框中_Javascript_Asp.net - Fatal编程技术网

javascript添加两个文本框值并显示在第三个文本框中

javascript添加两个文本框值并显示在第三个文本框中,javascript,asp.net,Javascript,Asp.net,如何在javascript/asp中添加两个文本框值并在第三个文本框中显示?我的代码在下面 function fill() { var txt8 = document.getElementById("TextBox8").value; var txt9 = document.getElementById("TextBox9").value; document.getElementById("TextBox10").value = txt8 + t

如何在javascript/asp中添加两个文本框值并在第三个文本框中显示?我的代码在下面

 function fill() {
        var txt8 = document.getElementById("TextBox8").value;
        var txt9 = document.getElementById("TextBox9").value;
        document.getElementById("TextBox10").value = txt8 + txt9;


    }

对于TextBox8和TextBox9,我都有onchange=“fill”,您必须调用函数,
onchange=“fill()”
注意,您需要将字符串转换为整数。值始终返回字符串


函数fill(){
var txt8=document.getElementById(“TextBox8”).value-0;
var txt9=document.getElementById(“TextBox9”).value-0;
document.getElementById(“TextBox10”).value=txt8+txt9;
}

函数调用后是否有一组括号?在javascript中,如果不使用括号跟随函数调用,则假定您正在引用变量。同样在将来,如果您正在努力调试javascript代码,您应该打开浏览器的javascript控制台,查看发生了什么以及抛出了什么错误(如果有)

<input type="text" id="TextBox8" onchange="fill()" />

<input type="text" id="TextBox9" onchange="fill()" />

为什么不使用jQUery?以下是一个示例:

function fill(){
var total=Number($('#TextBox9').val()) + Number($('#TextBox9').val());
$('#TextBox10').val(total);
}
函数和(){
var text1=document.getElementById(“”);
var text2=document.getElementById(“”);
如果(text1.value.length==0 | | text2.value.length==0){
text1.value=0;
text2.value=0;
}
var x=parseFloat(text1.value);
变量y=parseFloat(text2.value);
document.getElementById(“”).value=x+y;
}
文本框1
文本框2
文本框3
function fill(){
var total=Number($('#TextBox9').val()) + Number($('#TextBox9').val());
$('#TextBox10').val(total);
}
    function Sum() {
        var text1 = document.getElementById('<%= TextBox1.ClientID %>');
        var text2 = document.getElementById('<%= TextBox2.ClientID %>');
        if (text1.value.length == 0 || text2.value.length == 0) {
            text1.value = 0;
            text2.value = 0;
        }

        var x = parseFloat(text1.value);
        var y = parseFloat(text2.value);          

        document.getElementById('<%= TextBox3.ClientID %>').value = x + y;
    }




<table>
    <tr>
        <td style="width: 100px">
            TextBox1</td>
        <td>
            <asp:TextBox ID="TextBox1" runat="server" onkeyup="Sum()"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            TextBox2</td>
        <td>
            <asp:TextBox ID="TextBox2" runat="server" onkeyup="Sum()"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            TextBox3</td>
        <td>
            <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            <asp:Button ID="Button1" runat="server" Text="Show" Width="80px" OnClientClick="Sum()" />
        </td>
    </tr>
</table>