asp.net中的java脚本 [英] java script in asp.net

查看:70
本文介绍了asp.net中的java脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何在c#页面中调用java脚本函数

i有javascript函数

hello ,
how to call a java script function in c # page
i have a function of javascript

<script type="text/javascript">
        function go(loc) {
            document.getElementById('ifm').src = loc;
        }
    </script>



i希望在我的c#页面按钮点击事件中调用此函数并动态设置参数loc

我怎么能这样做



谢谢&问候

Srishti

推荐答案

这样的事情:

Something like this:
protected void Page_Load(object sender, EventArgs e)      
{
          System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof
           (Page), "script", "go(<yourparameter>)", true);
}



有关详细说明,请参阅这里 [ ^ ]


你不能从C#调用JS,因为C#代码在服务器端运行,直到服务器准备HTML到客户端。



在客户端的HTML内部有你的Javascript函数。

您可以做的是将代码设置为在HTML上的按钮的onClick事件上执行,从而在页面执行postBack到服务器之前在客户端执行代码。 />


Hers'是在Javascript中使用按钮的onclick事件的一个例子:

You can''t call JS from the C# since the C# code runs on the server side, until the HTML is prepared by the server to go to the client side.

Inside the HTML that goes to the client side there are your Javascript functions.
What you CAN do is set code to execute on the onClick event of the button on the HTML and thus execute code on the client side before the page does a postBack to the server.

Hers''s an example of using the onclick event of a button in Javascript:
<button onclick="myFunction()">Click me</button>





干杯,

Edo



Cheers,
Edo


这篇关于asp.net中的java脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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