如何在类文件中调用jquery函数 [英] How to call jquery function in a class file
本文介绍了如何在类文件中调用jquery函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好我已经创建了一个我想在整个应用程序中使用的javascript,所以我创建了一个返回字符串的类,如下所示
Hi all I have created a javascript which I want to use in my entire application, so I have created a class which returns string as follows
public static string ShowAlert(string pHeader, string pMessage)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script language='JavaScript' type='text/javascript'>");
sb.Append("example1('" + pHeader + "','" + pMessage + "')");
sb.Append("</Script");
return sb.ToString();
}
这是我的代码JFunction.JS
This is my code JFunction.JS
function example1(title, content) {
$.msgBox({
title: title,
content: content
});
}
现在点击按钮我只是按如下方式调用
Now on button click I am just calling as follows
Page.ClientScript.RegisterStartupScript(this.GetType(), "",ShowAlert(pHeader,pMessage) , true);
此示例我需要转换为动态的方式,以便它可以在任何页面上调用而无需编写函数
http ://jquerymsgbox.ibrahimkalyoncu.com/ [ ^ ]
推荐答案
.msgBox({
title:title,
content:content
});
}
.msgBox({ title: title, content: content }); }
现在点击按钮我只是按如下方式调用
Now on button click I am just calling as follows
Page.ClientScript.RegisterStartupScript(this.GetType(), "",ShowAlert(pHeader,pMessage) , true);
此示例我需要转换为动态的方式,以便它可以在任何页面上调用而无需编写函数
http ://jquerymsgbox.ibrahimkalyoncu.com/ [ ^ ]
您应该创建一个js文件,然后在您的母版页中为该文件添加一个include。在你的代码背后创建javascript总是一个黑客。如果您需要从每个页面访问ShowAlert方法,那么为页面创建自己的基类,并将其放在那里。当我以前做ASP.NET(很糟糕,我现在做MVC)时,我要做的第一件事就是创建一个自定义基页类,它返回一个强类型的母版页,并有我希望访问的其他帮助方法。 web项目。
You should create a js file, and then put an include to that file in your master page. Creating javascript in your code behind is always a hack. If you need your 'ShowAlert' method to be accessible from every page, then create your own base class for pages, and put it in there. When I used to do ASP.NET ( it sucks, I do MVC now ), the first thing I'd do is create a custom base page class that returned a strongly typed master page and had other helper methods I wanted access to across my web project.
你好,
尝试编写没有脚本标签的ShowAlert()方法,如下所示:
Hello,
Try writing ShowAlert() method without script tag as below :
public static string ShowAlert(string pHeader, string pMessage)
{
StringBuilder sb = new StringBuilder();
sb.Append("example1('" + pHeader + "','" + pMessage + "');");
return sb.ToString();
}
这篇关于如何在类文件中调用jquery函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文