表をクリックして、テーブルの列が増えていくプログラムを書きたいのですが、javascriptのエラーの意味が調べてもわかりません。エラーの原因について何かわかればご教示いただけますと幸いです。
データベースはMysqlで扱っており、ローカル開発環境で、MacOSXです。
エラー内容
Uncaught SyntaxError: Unexpected token <
ちなみにJavascriptのファイルを外部ファイルとして読み込んでいますが、直接phpのファイルに記入するとエラーが出ずに実行されます。
不要な<
はどこにもない気がするのですが、、、以下がjavascriptのファイルです。
外部ファイルとして読み込むと、mouseoverも効いていません。
ajax.index.js
<script> $(function(){ $('[id=click]') .mouseover(function(){ $(this).css('background','pink').css('cursor','pointer'); }) .mouseout(function(){ $(this).css('background','white'); }); $('[id=click]').click(function(){ $('table').append( $('<tr></tr>') .append($('<td></td>').text('テキスト')) .append($('<td></td>').text('テキスト')) .append($('<td></td>').text('テキスト')) .append($('<td></td>').text('テキスト')) .append($('<td></td>').text('テキスト')) ); }); }); </script>
以下がphpの内容です。外部ファイルのajax.index.phpではデータベースに接続しています。
index.php
<?php require 'ajax.index.php'; ?> <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <tittle>検索したい情報を入力してください</title> </head> <body> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="ajax.index.js"></script> <table> <tr> <th>エリア</th> <th>幼稚園部数</th> <th>保育園部数</th> <th>サークル部数</th> <th>その他部数</th> <th>計部数</th> </tr> <tr> <td>港区</td> <button type="submit" name="minato" id="minato"> <td id="click"><?php echo $Minato_k['sum(copies)']; ?></td> </button> <button type="submit" name="minato" id="minato"> <td id="click"><?php echo $Minato_n['sum(copies)']; ?></td> </button> <button type="submit" name="minato" id="minato"> <td id="click"><?php echo $Minato_c['sum(copies)']; ?></td> </button> <button type="submit" name="minato" id="minato"> <td id="click"><?php echo $Minato_o['sum(copies)']; ?></td> </button> <button type="submit" name="minato" id="minato"> <td id="click"><?php echo $Minato['sum(copies)']; ?></td> </button> </tr> </table> </body> </html>
エラー原因がわかればとても嬉しいです。
宜しくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/07 15:29