费了很大功夫,之前写的跟这个差不多,但是就是不能正常运行,找不到原因,这个搞定的记录一下
1 <html> 2 <head> 3 <title></title> 4 <meta name="generator" 5 content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39" /> 6 <script> 7 function myFunction() 8 { 9 var x,y; 10 x = document.getElementById(‘varX‘).value; 11 y = document.getElementById(‘varY‘).value; 12 document.getElementById(‘res‘).innerHTML = parseInt(x) + parseInt(y); 13 } 14 </script> 15 </head> 16 <body> 17 18 <p>请输入两个数:</p> 19 <p>x: 20 <input type=‘number‘ id=‘varX‘ /></p> 21 <p>y: 22 <input type=‘number‘ id=‘varY‘ /></p> 23 <button onclick=‘myFunction()‘>click</button> 24 <p id = ‘res‘>结果:</p> 25 <!-- <input type=‘text‘ id=‘res‘ /></p> --> 26 27 </body> 28 </html>
时间: 2024-10-15 12:22:21