Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript onClick在codeigniter中不工作_Javascript_Php_Jquery_Codeigniter 3 - Fatal编程技术网

Javascript onClick在codeigniter中不工作

Javascript onClick在codeigniter中不工作,javascript,php,jquery,codeigniter-3,Javascript,Php,Jquery,Codeigniter 3,当我尝试在php页面中使用onClick时,如下所示: <a href="javascript:void(0);" onClick="deleteCourse('<?php echo $row->courseId;?>');" class="delete">Delete</a> 它将显示错误,如 未捕获引用错误:未定义deleteCourse 在htmlanchorement.onclick,但当我在同一页面中使用onclick时,它工作正常 cour

当我尝试在php页面中使用
onClick
时,如下所示:

<a href="javascript:void(0);" onClick="deleteCourse('<?php echo $row->courseId;?>');" class="delete">Delete</a>
它将显示错误,如

未捕获引用错误:未定义deleteCourse

在htmlanchorement.onclick,但当我在同一页面中使用onclick时,它工作正常

courselist.php 该user.js已正确包含,我已在页面源代码中看到它。


 <a href="javascript:void(0);" onClick="deleteCourse(<?php echo $row->courseId;?>);" class="delete">Delete</a>

将整数传递给JS函数时不需要使用引号

检查包含的JS顺序。确保jquery js文件后面包含user.js//当我在同一页面中使用onClick时,它工作正常//这是什么意思?与CI无关。其清晰的javascript无法找到该函数。在这几点上,您的函数未加载。请重新检查页面源代码是否在user.js文件中有该函数。@AlaksandarJesusGene当我在同一courselist.php文件中使用该
deleteCourse
函数时,它就工作了。@GhanshyamBhava是的,它包含在所有jquery文件之后
<a href="javascript:void(0);" onClick="deleteCourse('<?php echo $row->courseId;?>');" class="delete">Delete</a>
function deleteCourse(course_id){
   alert('trying to delete course');
}
 <a href="javascript:void(0);" onClick="deleteCourse(<?php echo $row->courseId;?>);" class="delete">Delete</a>
<a href="javascript:void(0);" onClick="deleteCourse('<?php echo $row->courseId;?>');" class="delete">Delete</a>
<a href="javascript:void(0);" data-courseId="<?php echo $row->courseId;?>" class="delete">Delete</a>
$(document).on("click", ".delete", function(event){
 event.preventDefault();
 event.stopPropagation();
 courseId = $(this).attr("data-courseId");
 alert('trying to delete course');
//your logic for deleting the course.
});