window.location在js函数内部不起作用

时间:2016-09-23 14:06:17

标签: javascript php

<!DOCTYPE html>
<html>
<head>
<script>
//if i put window.location= "index.php" here not inside js function it worked but I need it to be inside a function
function newLoad() {
    window.location= "index.php"
}
</script>
</head>
<body>

<input type="button" value="press here" onclick="newLoad()">

</body>
</html>

任何想法如何让它在javascript函数中运行?

1 个答案:

答案 0 :(得分:0)

您的代码有效。 Howether,你不需要使用javascript。

<a href="index.php">
   <button>press here</button>
</a>