![](/img/trans.png)
[英]Is it possible to pass a Session variable (object) to an API as a parameter?
[英]Is it possible to pass variable as parameter in javascript function?
我有這個功能:
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,它根據所單擊的treenode獲得的值為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);
嘗試串聯:
ScriptManager.RegisterStartupScript(this, this.GetType(), "anyname", "show(" + nid + ")", true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.