简体   繁体   English

如何从aspx页面引用jQuery函数?

[英]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. 我在(chart.js)的另一个解决方案文件中有j-query函数test() ,该文件添加了主要项目的参考。 Now i want to call the test() method from default.aspx page. 现在我想从default.aspx页面调用test()方法。

This is my code. 这是我的代码。

chart.js chart.js之

function test(){

//for Example
}

default.aspx Default.aspx的

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

If i call the test method() from default.aspx page it is "undfined". 如果我从default.aspx页调用test method(),则它是“未定义的”。 how to call the j-query method which is located in another solution file but the same is added reference to the main project. 如何调用位于另一个解决方案文件中的j-query方法,但是添加了对主项目的引用。 Anyone could help on this.. 任何人都可以对此提供帮助。

Thanks, 谢谢,

Bharathi Bharathi

you should put reference to tht perticular js file at starting of the page like below :- 您应该在页面开始处放置指向垂直js文件的引用,如下所示:-

<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. 似乎您正在使用JS.page,并且正在尝试使用脚本对其进行调用。

If you want to have your chart.js called into the default.aspx page do it like this. 如果您希望将chart.js调用到default.aspx页面中,请执行以下操作。

<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. 您必须在脚本块之前添加该js文件(chart.js),该文件可能位于页面的head标签中。 like following 喜欢以下

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

and Make sure your jQuery file is added even before it. 并且确保您的jQuery文件已经添加。 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: 在aspx页面的头部添加以下内容:

    <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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