[英]Call a Jquery function inside the same (.js) file and another PHP file?
I have a js file with Jquery function now i have to call that function on document ready and inside another PHP file i tried below codes it worked for PHP file but for the JS file it is saying $.test is not a function
我有一个带有Jquery函数的js文件,现在我必须在准备好文档的文件中调用该函数,并在另一个PHP文件中调用了以下代码,该函数适用于PHP文件,但对于JS文件,它说
$.test is not a function
jq.js file for this error message was $.test is not a function
. 此错误消息的jq.js文件
$.test is not a function
。
$(document).ready(function(){
$.test();
$.test = function(){
alert('HELLO WORLD');
}
});
add.php file For this worked. add.php文件为此工作。
.....SOME PHP CODES HERE ....
<td class="del"><span class="fa fa-times"></span></td>
<script>
$('.delI').unbind().click(function(){
$.test();
});
</script>
I have to call this test() function inside the same JS file and in another PHP file too please give me a solution.. thanks. 我必须在相同的JS文件和另一个PHP文件中调用此test()函数,请给我一个解决方案..谢谢。
The problem is that you call $.test
before you defined it. 问题是您在定义
$.test
之前先调用它。 Call it after the definition: 在定义后调用它:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
$.test();
});
Simply do this: 只需执行以下操作:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
})();
Call the function after you define it, not before. 在定义函数之后调用函数,而不是在之前。
Or: 要么:
$(document).ready(function(){
$.test = function(){
alert('HELLO WORLD');
}
$.test();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.