Handleur de bouton JavaScript, erreur!
-
28-10-2019 - |
Question
Quelqu'un pourrait-il me dire mal avec:
<a href="javascript:void();" onclick="myFunc()"> Execute function </a>
Dans Chrome Inspecteur, l'erreur que j'obtiens est:
Syntaxerror non cinglable: jeton inattendu
Vous trouverez ci-dessous à quoi ressemble mon code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="root"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<a href="javascript:void();" onclick="myFunc()"> Execute function </a>
<script>
function myFunc() {
// some code here
}
</script>
</body>
</html>
La solution
<a href="javascript:void();" onclick="myFunc()"> Execute function </a>
<script>
function myFunc() {
// some code here
}
</script>
Mettez la balise d'ancrage de la balise de script, vous mettez des balises à l'intérieur de JavaScript, c'est pourquoi l'erreur est le résultat.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow