我收到以下错误
未捕获的类型错误:对象不是函数
在下面的代码中。
<html>
<head>
<title>Reverse</title>
</head>
<body>
<form name="rev1">
Enter the string : <input type="text" name="str">
<input type="button" value="click" onclick="rev1()" />
这是我发现错误的地方:
reverse of given string : <input type="text" name="res">
</form>
<script type="text/JavaScript">
function rev1(){
//var a=rev1.str.value;
//document.write("hello");
alert("hello");
}
</script>
</body>
</html>
可能导致此问题的原因以及如何解决?
答案 0 :(得分:1)
重命名表单,或完全删除它。 rev1
引用给定脚本中的form
元素。
演示:Original - Working
(单击按钮直接调用该功能)
编辑:我已经看到这个问题引发了很多讨论,所以我也会留下一些参考资料: