# 添加两个数字连接它们而不是计算总和

function myFunction() { var y = document.getElementById("txt1").value; var z = document.getElementById("txt2").value; var x = y + z; document.getElementById("demo").innerHTML = x; }
<p> Click the button to calculate x. <button onclick="myFunction()">Try it</button> </p> <p> Enter first number: <input type="text" id="txt1" name="text1" value="1"> Enter second number: <input type="text" id="txt2" name="text2" value="2"> </p> <p id="demo"></p>

### 18 Solutions collect form web for “添加两个数字连接它们而不是计算总和”

var x = +y + +z;

var i=2; var j=3; var k = Number(i) + Number(j); // 5

var x = parseInt(stringValueX, 10); var y = parseInt(stringValueY, 10); alert(x + y);

var y = parseInt(document.getElementById("txt1").value); var z = parseInt(document.getElementById("txt2").value); var x = y + z;

var result = parseInt("1") + parseInt("2"); console.log(result ); // Outputs 3

<html> <body> <p>Click the button to calculate x.</p> <button onclick="myFunction()">Try it</button> <br/> <br/>Enter first number: <input type="text" id="txt1" name="text1">Enter second number: <input type="text" id="txt2" name="text2"> <p id="demo"></p> <script> function myFunction() { var y = document.getElementById("txt1").value; var z = document.getElementById("txt2").value; var x = +y + +z; document.getElementById("demo").innerHTML = x; } </script>

var x = y + z; 应该是var x = parseInt(y) + parseInt(z);

<!DOCTYPE html> <html> <body> <p>Click the button to calculate x.</p> <button onclick="myFunction()">Try it</button> <br/> <br/>Enter first number: <input type="text" id="txt1" name="text1">Enter second number: <input type="text" id="txt2" name="text2"> <p id="demo"></p> <script> function myFunction() { var y = document.getElementById("txt1").value; var z = document.getElementById("txt2").value; var x = parseInt(y) + parseInt(z); document.getElementById("demo").innerHTML = x; } </script> </body> </html>

var y = parseInt(document.getElementById("txt1").value); var z = parseInt(document.getElementById("txt2").value); var x = (y +z); document.getElementById("demo").innerHTML = x;`

\$('input[name="yourname"]').keyup(function(event) { /* Act on the event */ var value1 = \$(this).val(); var value2 = \$('input[name="secondName"]').val(); var roundofa = +value2+ +value1; \$('input[name="total"]').val(addition); });

var x = y + z;

var x = (y)+(z);

var x = parseInt(y) + parseInt(z); [final soulution, as everything us]

function myFunction() { var y = document.getElementById("txt1").value; var z = document.getElementById("txt2").value; if((x.search(/[^0-9]/g) != -1)&&(y.search(/[^0-9]/g) != -1)) var x = Number(y)+ Number(z); else alert("invalid values...."); document.getElementById("demo").innerHTML = x; }

<!DOCTYPE html> <html> <body> <p> Add Section </p> <label>First No :</label> <input id="txt1" type="text"/><br /> <label>Second No :</label> <input id="txt2" type="text"/><br /> <input type="button" name="Add" value="Add" onclick="addTwoNumber()"/> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Date(); } function addTwoNumber(){ var a = document.getElementById("txt1").value; var b = document.getElementById("txt2").value; var x = Number(a) + Number(b); document.getElementById("demo").innerHTML = "Add Value: " + x; } </script> </body> </html>

var result=eval(num1)+eval(num2);
<head> <script type="text/javascript"> function addition() { var a = parseInt(form.input1.value); var b = parseInt(form.input2.value); var c = a+b document.write(c); } </script> </head> <body> <form name="form" method="GET"> <input type="text" name="input1" value=20><br> <input type="text" name="input2" value=10><br> <input type="button" value="ADD" onclick="addition()"> </form> </body> </html>

<html> <body> <p>Click the button to calculate x.</p> <button onclick="myFunction()">Try it</button> <br/> <br/>Enter first number: <input type="text" id="txt1" name="text1"> <br>Enter second number: <input type="text" id="txt2" name="text2"> <p id="demo"></p> <script> function myFunction() { var y = parseInt(document.getElementById("txt1").value); var z = parseInt(document.getElementById("txt2").value); var x = y + z; document.getElementById("demo").innerHTML = x; } </script> </body> </html>

function myFunction() { var y = document.getElementById("txt1").value; var z = document.getElementById("txt2").value; var x = parseFloat(y) + parseFloat(z); document.getElementById("demo").innerHTML = x; }

<p> Click the button to calculate x. <button onclick="myFunction()">Try it</button> </p> <p> Enter first number: <input type="text" id="txt1" name="text1" value="1"> Enter second number: <input type="text" id="txt2" name="text2" value="2"> </p> <p id="demo"></p>
<input type="text" name="num1" id="num1" onkeyup="sum()"> <input type="text" name="num2" id="num2" onkeyup="sum()"> <input type="text" name="num2" id="result"> <script> function sum() { var number1 = document.getElementById('num1').value; var number2 = document.getElementById('num2').value; if (number1 == '') { number1 = 0 var num3 = parseInt(number1) + parseInt(number2); document.getElementById('result').value = num3; } else if(number2 == '') { number2 = 0; var num3 = parseInt(number1) + parseInt(number2); document.getElementById('result').value = num3; } else { var num3 = parseInt(number1) + parseInt(number2); document.getElementById('result').value = num3; } } </script>
• 如何在CSS中应用字体反别名效果？
• 如何让手风琴在closures所有菜单的情况下加载？