我有这个功能:
protected void mytv_SelectedNodeChanged(object sender, EventArgs e)
{
TreeView tv = sender as TreeView;
var nid = tv.SelectedNode.Value;
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", "show(nid)", true);
}
如您所见,我有一个变量 nid,它根据单击的树节点获得不同的值 1,2,3。
我可以将该 nid 变量值作为参数直接传递给 javascript 函数作为 show(nid) 吗?
如果不是,我该怎么办?
我的javascript函数如下:
function show(nid)
{
if (nid == 4) {
alert('testing');
}
else
{
alert('what???');
}
}
最佳答案
//for string value
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", string.Format("show('{0}')", nid), true);
//for int value
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", string.Format("show({0})", nid), true);
关于c# - 是否可以在javascript函数中将变量作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24505967/