积极答复者
这怎么传值???

问题
-
我是初学者,请问这怎么传值。
这个Js 是写在 网页里的。我准备在后台代码写个方法,将3个参数传给被写死的参数位置new GLatLng(33.0, 106.0), 3
代码:
<script type="text/javascript">
function initialize()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("mapContainer"));
map.setCenter(new GLatLng(33.0, 106.0), 3); // “(33.0,106,)3” 是被写死的
}
}
</script>
写个什么样的方法,可以改变 上面 被写死的 内容?
"(33.0,106,)3” 是地图坐标地址,我需要将此3个量变为变量。
请帮忙。- 已移动 Sheng Jiang 蒋晟Moderator 2009年8月12日 19:01 web开发问题 (发件人:Visual C#)
答案
-
HTML-----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("mapContainer")); map.setCenter(new GLatLng(x, y), z); // “(33.0,106,)3” 是被写死的 } } </script> </head> <body onload="initialize();"> <form id="form1" runat="server"> </form> </body> </html>
-----------------------------------------------------------------CS
-----------------------------------------------------------------protected void Page_Load(object sender, EventArgs e) { // 除了这种方式你也可以在后台直接输出整个脚本块 int x = 33, y = 106, z = 3; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "InitVals", String.Format("var x = {0}; var y = {1}; var z = {2};", x, y, z), true); }
知识改变命运,奋斗成就人生!- 已建议为答案 Raymond TangModerator 2009年8月13日 1:49
- 已标记为答案 KeFang Chen 2009年8月13日 2:38
-
您好,另一种写法请参考:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormJS.aspx.cs" Inherits="WebApplication1.WebFormJS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript">
function initialize()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("mapContainer"));
map.setCenter(new GLatLng(<%=x %>, <%=y %>), <%=z %>); // “(33.0,106,)3” 是被写死的
}
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
以下codebehind代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApplication1
{
public partial class WebFormJS : System.Web.UI.Page
{
protected int x ;
protected int y ;
protected int z ;
protected void Page_Load(object sender, EventArgs e)
{
x = 33;
y = 106;
z = 3;
}
}
- 已建议为答案 Raymond TangModerator 2009年8月13日 1:49
- 已标记为答案 KeFang Chen 2009年8月13日 2:38
全部回复
-
HTML-----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> function initialize() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("mapContainer")); map.setCenter(new GLatLng(x, y), z); // “(33.0,106,)3” 是被写死的 } } </script> </head> <body onload="initialize();"> <form id="form1" runat="server"> </form> </body> </html>
-----------------------------------------------------------------CS
-----------------------------------------------------------------protected void Page_Load(object sender, EventArgs e) { // 除了这种方式你也可以在后台直接输出整个脚本块 int x = 33, y = 106, z = 3; this.ClientScript.RegisterClientScriptBlock(this.GetType(), "InitVals", String.Format("var x = {0}; var y = {1}; var z = {2};", x, y, z), true); }
知识改变命运,奋斗成就人生!- 已建议为答案 Raymond TangModerator 2009年8月13日 1:49
- 已标记为答案 KeFang Chen 2009年8月13日 2:38
-
您好,另一种写法请参考:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebFormJS.aspx.cs" Inherits="WebApplication1.WebFormJS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript">
function initialize()
{
if (GBrowserIsCompatible())
{
var map = new GMap2(document.getElementById("mapContainer"));
map.setCenter(new GLatLng(<%=x %>, <%=y %>), <%=z %>); // “(33.0,106,)3” 是被写死的
}
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
以下codebehind代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace WebApplication1
{
public partial class WebFormJS : System.Web.UI.Page
{
protected int x ;
protected int y ;
protected int z ;
protected void Page_Load(object sender, EventArgs e)
{
x = 33;
y = 106;
z = 3;
}
}
- 已建议为答案 Raymond TangModerator 2009年8月13日 1:49
- 已标记为答案 KeFang Chen 2009年8月13日 2:38