我想在我的最终答案中添加一个$,它现在在警告消息中返回答案为500.00,具体取决于
<HTML>
<HEAD>
<TITLE>Simple Adder</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function CalculateSum(Atext, Btext)
{
var A = parseFloat(Atext);
var B= A * .03+.30+A;
alert(B.toFixed(2));
}
function ClearForm(form)
{
form.input_A.value = "";
form.Answer.value = "";
}
// end of JavaScript functions -->
</SCRIPT>
</HEAD>
<BODY>
<P><FONT SIZE="+2">Credit Card Payment Calculator</FONT></P>
<FORM NAME="Calculator" METHOD="post">
<P>Enter Base Rent: <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P>
<P><INPUT TYPE="button" VALUE="Calculate Rent & Fees Payment" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form)"></P>
</FORM>
</BODY>
</HTML>
答案 0 :(得分:4)
alert('$' + B.toFixed(2));
“toFixed()”函数返回一个字符串,因此您只需将“$”添加到该字符串中。
有点难以分辨你所要求的是什么
答案 1 :(得分:2)
alert('$' + B.toFixed(2));
应该工作