如何访问该文件中的外部javascript文件和函数到aspx页面 [英] How to access a external javascript file and functions in that file to aspx page

查看:86
本文介绍了如何访问该文件中的外部javascript文件和函数到aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一个javascript文件和aspx页面,我们必须访问java脚本文件并调用该js文件中的函数。

怎么办?

If there is a javascript file and aspx page we have to access the java script file and call the functions in that js file.
How can In do it?

推荐答案

将JS文件包含在页面的head部分,你可以调用其中的方法。例如,如果脚本文件名为MyJScriptFile.js位于Scripts文件夹下,请将其包含在aspx页面的head部分中,如:



Include that JS file in the head section of your page and you can call the methods in it. For example if you script file named MyJScriptFile.js is under Scripts folder, include it in the head section of your aspx page like:

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





之后你就可以使用了e通过以下方式从您的aspx页面中执行此操作:



1)如果按钮是HTML控件





After that you can use the functions in it from your aspx page in the following way:

1) If the button is an HTML control

<input type = "button" id = "myButton" value = "Click"  önclick = "YourJavaScriptFunction()" />





2)如果按钮是服务器控制



在aspx.cs的页面加载方法中写下以下内容





2) If the button is a server control

Write the following in the page load method of aspx.cs

If(!IsPostBack)
{
YourButtonID.Attributes.Add("onclick","YourJavaScriptFunction();");
}


这篇关于如何访问该文件中的外部javascript文件和函数到aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆