how to call a jquery function from javascript
Let's say I created a function in jQuery table.js file.
function createCookie(name) {
//...
}
ho开发者_开发百科w would I call this function from JavaScript in my main.php file? I tried calling it simply like
<script type="text/javascript">
createCookie("john");
</script>
I have included the table.js file but it's not working! I know that jQuery functions are called via .changeRows(5)
and for that I have to change my function definition but in that case what object will be associated with this function as I am using this to create cookies!
<script type="text/javascript">
createCookie("john");
</script>
not
<script type"text/javascript>
createCookie("john");
</script>
Firstly, there is no such thing as a 'JQuery function'. A jQuery function IS as JavaScript function.
For the purposes of your question, however, it looks like you are probably including the JavaScript file in you PHP file AFTER the script block. so when the script block executes, the files hasn't yet been loaded.
You are also missing an =
after the word type
in your HTML and a closing "
after javascript
First off all, jQuery is not a language. it's a library for javascript. Hence, you created a javascript function.
Since you're using jquery, just add
$(document).ready(function() {
createCookie("john");
});
to the end of your js file
for standard js you could use
document.onload = function(){
createCookie("john");
};
精彩评论