未捕获的ReferenceError:JQuery

时间:2012-02-19 10:56:07

标签: php jquery mysql codeigniter

部首:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://mysite.com/public/delete.js" type="text/javascript"></script>

查看:

<ol>
<?php foreach($sqlplaces->result() as $place): ?>
 <li id="place-<? echo $place->id; ?>">
  <h3><?php echo anchor('/home/one/place/'.$place->id.'/'.$place->userid.'/'.$place->name,  $place->name); ?>
   <span style="float:right;"><a class="delete" id="<? echo $place->id; ?>" href="#"><img src="<? echo base_url(); ?>images/database_close_32.png" alt="Delete" /></a></span>
  </h3>
 </li>
<?php endforeach; ?>
</ol>

delete.js:

$(document).ready(function() {

    $("a.delete").live('click', function() {
            var deleteId = $(this).attr('id');
            $("li#place-" + deleteID).addClass("hide");

            $.post(base_url + "index.php/home/delete", { delid : deleteId }, function(data)
            {
                    alert(data);
            }, "json");

    return false;
             });


});

我试图隐藏<li id="place-<? echo $place->id; ?>">元素,但我无法弄清楚为什么Uncaught ReferenceError:deleteID未定义出现。如果我删除$("li#place-" + deleteID).addClass("hide");deleteID将传递给$post,并且该条目将从数据库中删除。

1 个答案:

答案 0 :(得分:1)

因为你拼写错误deleteID,JavaScript变量区分大小写。您使用小写d声明它deleteId

这应该这样做:

$("li#place-" + deleteId).addClass("hide");