将Java脚本插入部分 [英] Insert java script into section
本文介绍了将Java脚本插入部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨! :)
如何动态地将 java脚本代码插入 .aspx 页面的部分? :confused:
感谢您的回答...
Hi! :)
How can I dynamically insert the java script code into section of .aspx page ? :confused:
Thanks for answer...
推荐答案
使用this.ClientScript.RegisterClientScriptBlock
放置一个JavaScript块.
另一种方法是将make head用作runat ="server"并在页面加载时从代码隐藏访问它:
usethis.ClientScript.RegisterClientScriptBlock
to put a javascript block.
Another way is to use make head as runat="server" and access this from codebehind while the page loads :
HtmlGenericControl thehead = this.FindControl("serverid") as HtmlGenericControl;
thehead.Controls.Add("your block");
简单的. :rose::)
Simple. :rose: :)
ClientScript.RegisterStartupScript(Me.GetType(),"scripts",< script language =''javascript''>"& _
"window.open("&" URL,"窗口名称,"& _
''width = 650,height = 700,resizable = no'')"& _
</script>")
或
button.OnClientClick ="Java脚本代码"
ClientScript.RegisterStartupScript(Me.GetType(), "scripts", "<script language=''javascript''>" & _
"window.open(''" & "URL", ''Window Name'', " & _
"''width=650, height=700, resizable=no'')" & _
"</script>")
or
button.OnClientClick=" java script Code"
这种方式如何?
在.ASPX中:
How about this way?
In .ASPX :
<head>;
<title>Untitled Page</title>
<asp:Literal ID="_literal" runat="server"></asp:Literal>
</head>
在.CS中:
In .CS :
protected void Page_Load(object sender, EventArgs e)
{
_literal.Text = "<script language=''javascript''>alert(''Hello!'');</script>";
}
似乎有效...
seems to work...
这篇关于将Java脚本插入部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文