此代码仅使我链接地址但不运行该功能。 (最后一个alert()
函数没有运行。)
我需要这个警报,我做错了什么?
这是我的代码:
<html>
<head>
<title>Laboratorul nr_3</title>
<meta charset="utf-8"/>
<script language="javascript"><!--
function ex1()
{
num = prompt("Input the number");
result = num * 3;
alert(num + " x " + 3 + " = " + result);
num2 = prompt("Input number to add");
result2 = num * 3 + parseint(num2);
alert(num + " x " + 3 + " + " num2 " = " + result2);
}
//--></script>
</head>
<body>
<a href="http://google.com" onclick="javascript:ex1()">link</a>
</body>
</html>
答案 0 :(得分:0)
您必须取消本机操作(在链接之后):
function ex1() {
// code...
return false;
}
或使用不做任何事情的其他元素,可能是<button>
或<div>
。