无法调用javascript函数

时间:2011-11-01 00:40:19

标签: javascript-events javascript

页面来源:

<html>
<head>
<title>Admin Search Results</title>

<script type="text/javascript">
function delete()
{     
    alert("abc");
}
</script>
</head>
<body>
<h1>Admin Search Results</h1>
<form id="modDel" action="modDel.pl" method="post" onsubmit="return delete()">
<table border="1">
<tr>
<th>User Name</th>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>Password</th>
<th>Blocked</th>
<th>Modify</th>
<th>Delete</th>
</tr>
<tr>
<input type="hidden" id="un_0" name="un_0" value="aa">
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>aa</td>
<td>0</td>
<td><input type="submit" name="modify_0" value="Modify"></td>
<td><input type="checkbox" id="delete_0" name="delete_0" value="Yes"></td>
</tr>
<tr>
<input type="hidden" id="un_1" name="un_1" value="a">
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>a</td>
<td>0</td>
<td><input type="submit" name="modify_1" value="Modify"></td>
<td><input type="checkbox" id="delete_1" name="delete_1" value="Yes"></td>
</tr>

</table>
<input type="hidden" id="count" name="count" value="1">
<input type="submit" id="delete" name="delete" value="Delete Selected Accounts" onclick="delete()">
<button type="button" onclick="delete()">Display Date</button>
</form>
</body>
</html>

它由两个模板的perl脚本生成(一个用于表)。

我想要的只是在某些事件上发生一些事情。我添加了onsubmit和onclick但是都没有工作。

我确定我只是错过了一些小东西,但我看不到它。 我正在使用chrome,顺便说一句。

编辑:我可以通过将js代码直接添加到onclick / onsubmit引号中来实现它。

1 个答案:

答案 0 :(得分:3)

这里的问题是delete是JavaScript中的保留字。尝试使用其他函数名称。此外,return函数中不需要onsubmit,只需直接调用该函数即可。

<script type="text/javascript">
function deleteFunc()
{     
    alert("abc");
}
</script>
</head>
<body>
<h1>Admin Search Results</h1>
<form id="modDel" action="modDel.pl" method="post" onsubmit="deleteFunc()">
相关问题