document.getElementById(" toai")。innerHTML = document.getElementById(" toai")。value

时间:2017-06-16 03:31:11

标签: javascript

<script>
function toai()
{
var Fr_amt_invt  = document.getElementById("Fr_amt_invt").value;
var Re_amt_invt  = document.getElementById("Re_amt_invt").value;
var totaltoai = +Fr_amt_invt + +Re_amt_invt;
document.getElementById("toai").innerHTML=+totaltoai;
}

</script>

函数toai()结果是.innerHTML我希望得到.value格式,以便在表单输入中使用。

1 个答案:

答案 0 :(得分:0)

您可以document.getElementById("toai").innerHTML=+totaltoai;代替toai()功能中的return

<script>
function toai()
{
var Fr_amt_invt  = document.getElementById("Fr_amt_invt").value;
var Re_amt_invt  = document.getElementById("Re_amt_invt").value;
Fr_amt_invt = parseFloat(Fr_amt_invt);
Re_amt_invt = parseFloat(Re_amt_invt);
var totaltoai = (Fr_amt_invt + Re_amt_invt);
totaltoai = parseFloat(totaltoai);
//document.getElementById("toai").innerHTML=+totaltoai; // delete this
return totaltoai;
}

然后你可以做document.getElementById('some-inputs-id').value = toai();