我有一个带有Jquery函数的js文件,现在我必须在文档上调用该函数,在另一个PHP文件中,我尝试了以下代码,它适用于PHP文件,但对于js文件,它说$.test is not a function
此错误消息的jq.js文件为$.test is not a function
。
$(document).ready(function(){
$.test();
$.test = function(){
alert('HELLO WORLD');
}
});
add.php文件为此工作。
.....SOME PHP CODES HERE ....
<td class="del"><span class="fa fa-times"></span></td>
<script>
$('.delI').unbind().click(function(){
$.test();
});
</script>
我必须在同一个JS文件和另一个PHP文件中调用这个test()函数。请给我一个解决方案。。谢谢
问题是在定义$.test
之前调用它。在定义之后调用它:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
$.test();
});
只需执行以下操作:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
})();
在定义函数之后而不是之前调用它。
或者:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
$.test();
});