简体   繁体   中英

how to refer the jquery function from the aspx page?

I have the j-query function test() in (chart.js) another solution file which is added the reference of main projects. Now i want to call the test() method from default.aspx page.

This is my code.

chart.js

function test(){

//for Example
}

default.aspx

<script>
test(); //call chart.js function
</script>

If i call the test method() from default.aspx page it is "undfined". how to call the j-query method which is located in another solution file but the same is added reference to the main project. Anyone could help on this..

Thanks,

Bharathi

you should put reference to tht perticular js file at starting of the page like below :-

<script type="text/javascript" src="chart.js" />
<script>
test(); //call chart.js function
</script>

Try this

<script type="text/javascript" src="chart.js">


$(document).ready(function()
   {
      test();
   });
</script>

It seems like you are using a JS.page and that you are trying to call it with a script.

If you want to have your chart.js called into the default.aspx page do it like this.

<script src="assets/chart.js"></script>

place this in the head sections

You have to add that js file (chart.js) before your script block, may be in head tags of page. like following

<script type="text/javascript" src="chart.js" />

and Make sure your jQuery file is added even before it. so it should be like following

<script type="text/javascript" src="jQuery.js" />
<script type="text/javascript" src="chart.js" />
<script type="text/javascript">
  test(); //call chart.js function
</script>

In the head section of your aspx page add this:

    <script type="text/javascript" src="chart.js" />//add reference of the chart.js file

   <script type="text/javascript" language="javascript">
          test(); //call chart.js function
    </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM