答案 0 :(得分:0)
function add() {
var x = document.getElementById("txt1").value;
var count = 0;
x = x.match(/[+\-]*(\.\d+|\d+(\.\d+)?)/g) || [];
while (x.length) {
count += parseFloat(x.shift());
}
document.getElementById("demo1").innerHTML = count;
}

<input type="text" id="txt1" name="txt1" />
<button onclick="add()">Try</button>
<p id="demo1">para</p>
&#13;