我真的很新鲜的Web开发,我试图用Javascript来改变一些输入的文本。这里是我的代码必须做的一个例子Javascript改变所有输入的文本
<!DOCTYPE html>
<html>
<body>
<p>Click the button to replace "R$" with "" in the field below:</p>
<input id="demo" value="R$ 1223,43"></input>
<input id="demo1" value="R$ 134523,67"></input>
<input id="demo2" value="R$ 12453,41"></input>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var x=document.getElementByTagName("input")
for(var i = 0; i < x.length; i++) {
var str=x[i].innerHTML;
var n=str.replace(",",".");
var n1 = n.replace("R$ ","");
document.getElementById("demo").innerHTML=n1;
}
}
</script>
</body>
</html>
所以,我想撤回“R $”并将“,”替换为“。”。对于一些数学运算。我必须在我的代码中完成所有输入。
.value的,没有.innerHTML - 我强烈建议通过http://w3fools.com [MDN](https://developer.mozilla.org/) – mplungjan 2013-04-11 12:12:13