比如在前台写了一个js方法
function test(name)
{
alert(name)
}
如何在后台实现调用这个方法,并传参
有办法response.write(string str)来实现吗,具体怎么实现?
function test(name)
{
alert(name)
}
如何在后台实现调用这个方法,并传参
有办法response.write(string str)来实现吗,具体怎么实现?
调试欢乐多
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "test('name')",true);
response.write str
生成的脚本是不是在<html></html>外面了,破坏了文档结构了。
Page.ClientScript.RegisterStartupScript(this.GetType(), "", "test('name')",true);
这样不行么
protected void Button1_Click(object sender, EventArgs e)
{
string str = "window.onload=function(){test('xxx')}";
Response.Write(str);
}
string str = "<script type='text/javascript'>window.onload=function(){test('xxx')}</script>";
Response.Write(str);
这样写如7楼所说会破坏文档结构,在顶层输出js
你可以按他的做法来
或者弄个label服务器控件什么的,把他的text属怀设置为这段js字符
那如果我现在想在B页面点击一个按据来调用A页面的js方法,有没办法呢?
经过自己测试如下:
1.aspx.cs文件的内容为:
protected void Page_Load(object sender, EventArgs e)
{
this.Page.ClientScript.RegisterClientScriptInclude("test", "JScript1.js");
string name = "tong";
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "test", "test('"+name+"');",true);
}
2.JScript1.js文件的内容为:
function test(name)
{
alert(name);
}
3.JScript.js文件和aspx文件在同一目录下。