任何人都可以告诉以下代码中的问题...当我在浏览器中运行程序时出现一个空白的白色屏幕...我不知道为什么它不起作用...我不是很确定语法...
我不想通过任何事件调用该函数..我只想编写一个函数并通过手动调用来调用它...
<html>
<head>
<script language="javascript" type="text/javascript">
function salin()
{
var sal = prompt("Enter your current salary - ","");
var in = prompt("Enter the increment % - ","");
sal = parseInt(sal);
in = parseInt(in);
var nsal = sal +( sal*(in /100));
alert("Your new salary is - " + nsal);
}
salin();
</script>
</head>
<body>
</body>
</html>
答案 0 :(得分:5)
问题似乎出在这一行in = parseInt(in);
in是javascript中的保留关键字,用于返回布尔值。将其替换为其他变量名称
答案 1 :(得分:3)
我创造了这个小提琴......
它的工作。您使用的是保留的javascript关键字
function salin()
{
var sal = prompt("Enter your current salary - ","");
var values = prompt("Enter the increment % - ","");
sal = parseInt(sal);
values = parseInt(values);
var nsal = sal +( sal*(values /100));
alert("Your new salary is - " + nsal);
}
salin();
答案 2 :(得分:0)
请改为尝试:
function salin()
{
var sal = prompt("Enter your current salary - ","");
var income = prompt("Enter the increment % - ","");
sal = parseInt(sal);
income = parseInt(income);
var nsal = sal +( sal*(income /100));
return "Your new salary is - " + nsal;
}
alert(salin());
注意我添加了return
并将alert()
放在函数调用上。我也将“in”改为“income”
答案 3 :(得分:0)
&#39;在&#39;是保留关键字。将其更改为其他变量名称
<body>
<script language="javascript" type="text/javascript">
function salin()
{
var sal = prompt("Enter your current salary - ","");
var in1 = prompt("Enter the increment % - ","");
sal = parseInt(sal);
in1 = parseInt(in1);
var nsal = sal +( sal*(in1 /100));
alert("Your new salary is - " + nsal);
}
salin();
</script>
</body>