JavaScript onClick功能不起作用

时间:2015-05-11 09:12:46

标签: javascript html web

<script language="javascript" type="text/javascript">
function delete() {
var newwindow;
newwindow=window.open();

}

function edit(){
}
</script>

[...]

   <table class="table table-striped">
      <thead>
      <th>Id</th>
      <th>Titel</th>
      <th>Ort</th>
      <th>Referenzcode</th>
      <th>Bearbeiten</th>
      <th>L�schen</th>
      </thead>
      <tbody>
          <c:forEach items="${vacancies}" var="vac">
          <spring:url value="/vac" htmlEscape="true" var="vacEdit" />
          <spring:url value="/vac/${vac.id}" htmlEscape="true" var="vacDelete" />
          <tr>
              <td><c:out value="${vac.id}"/></td>
              <td><c:out value="${vac.titel}"/></td>
              <td><c:out value="${vac.location}"/></td>
              <td><c:out value="${vac.referenceCode}"/></td>
              <td><input type="button" name="Bearbeiten" value="Edit" onclick="edit();"></td>
              <td><input type="button" name="Loeschen" value="Delete" onclick="delete();"></td>
          </tr>
          </c:forEach>
      </tbody>
  </table>

谷歌Chrome浏览器的JavaScript控制台抛出了这三个错误:

Uncaught SyntaxError: Unexpected token delete vacAdmin:23
Uncaught ReferenceError: edit is not defined  vacAdmin:122 
Uncaught SyntaxError: Unexpected token )    vacAdmin:123

为什么onclick方法没有调用或找到edit()delete()函数的任何建议?

1 个答案:

答案 0 :(得分:4)

问题是您不能使用delete等保留语言作为标识符。在javascript delete中是删除对象属性的运算符。

将您的功能重命名为deleteVacancy这样的功能,它将起作用:

<input type="button" name="Loeschen" value="Delete" onclick="deleteVacancy();">