如何调用后面从code这个javascript函数 [英] How to call this javascript function from code behind

查看:94
本文介绍了如何调用后面从code这个javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网页上放置的JavaScript创建的控件(http://www.dariancabot.com/projects/jgauge_wip/)。

 < D​​IV CLASS =jgauge>< / DIV>$(文件)。就绪(函数(){
    VAR CTL;
    CTL =新jGauge();
    ctl.init();
)}

比方说,我需要一些参数传递给的init 。像... ctl.init(A,B); 从code后面,我怎么能做到这一点?我想这样的事情...

 字符串SCRIPT2 =的String.Format(的init({0},{1}'),参数1,参数2);this.Page.ClientScript.RegisterStartupScript(this.GetType(),初始化控制,SCRIPT2,真正的);

但它不工作。我:

 的ReferenceError:初始化没有定义


解决方案

在init是jGauge实例中的方法。所以,你叫那些mathode之前必须实例。尝试波纹管:

 字符串SCRIPT2 =的String.Format(CTL变种; CTL =新jGauge(); ctl.init({0},{1}');,参数1 ,参数2);
this.Page.ClientScript.RegisterStartupScript(this.GetType(),初始化控制,SCRIPT2,真正的);

I'm putting javascript created controls (http://www.dariancabot.com/projects/jgauge_wip/) on my page.

<div class="jgauge" ></div>

$(document).ready(function () {  
    var ctl; 
    ctl = new jGauge();   
    ctl.init();
)}

Let's say I need to pass few parameters to init. like... ctl.init(a, b); from code behind, how can I achieve that? I tried something like this...

string script2 = String.Format("init('{0}','{1}')", param1, param2);

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "initialize control", script2, true);

But it's not working. I got:

ReferenceError: init is not defined

解决方案

The init is a method inside jGauge instance. So you must instantiate before you call those mathode. Try bellow:

string script2 = String.Format("var ctl; ctl = new jGauge();  ctl.init('{0}','{1}');", param1, param2);
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "initialize control", script2, true);

这篇关于如何调用后面从code这个javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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