0

誰が何が問題なのか教えてください:

<a href="javascript:void();" onclick="myFunc()"> Execute function </a>

Chromeインスペクターで表示されるエラーは次のとおりです。

キャッチされていない SyntaxError: 予期しないトークン <

以下は私のコードがどのように見えるかです:

<!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>  
4

1 に答える 1

0
<a href="javascript:void();" onclick="myFunc()"> Execute function </a>

<script>
function myFunc() { 
    // some code here
}    
</script>

Put the anchor tag out of script tag, you are putting tags inside javascript so that is why error is result.

于 2011-03-23T07:23:35.527 に答える