我有以下代码,可以在 asp.net 中生成动态创建的图像按钮和面板:-
Panel panBlocks = new Panel();
panBlocks.ID = "PanBlockQuestionID" + recordcount.ToString();
panBlocks.Width = 1300;
panBlocks.Height = 50;
panBlocks.BackColor = Color.Pink;
ImageButton cmdBlocks = new ImageButton();
cmdBlocks.ImageUrl = "~/Images/block3.png";
cmdBlocks.ID = "lblImg" + recordcount.ToString();
cmdBlocks.Attributes["class"] = "liQuestionsLabel2";
cmdBlocks.Width = 30;
cmdBlocks.Attributes.Add("OnMouseOver", "showPanel(" + "CPH_Body_" + panBlocks.ClientID.ToString() + ")");
cmdBlocks.Attributes.Add("OnMouseOut", "hidePanel();");
li.Controls.Add(cmdBlocks);
li.Controls.Add(panBlocks);
当我将鼠标悬停在图像上时,我希望它显示特定的面板。我已添加 "CPH_Body_"+ panBlocks.ClientID.ToString()
作为属性。
我有以下 JavaScript 代码:
function showPanel(PanelID)
{
document.getElementById("CPH_Body_liQuestions1").style.height = "40px";
}
如何在 javascript 中检索 PanelID
,因为它看起来像一个数组。我需要检索它,以便我知道要显示哪个面板。
最佳答案
IIUC(!!):
更改此:
cmdBlocks.Attributes.Add("OnMouseOver", "showPanel(" + "CPH_Body_" + panBlocks.ClientID.ToString() + ")");
致:
cmdBlocks.Attributes.Add("OnMouseOver", "showPanel('" + panBlocks.ClientID.ToString() + "')");
并更改此:
function showPanel(PanelID)
{
document.getElementById("CPH_Body_liQuestions1").style.height = "40px";
}
至
function showPanel(PanelID)
{
document.getElementById(PanelID).style.height = "40px";
}
关于javascript - 如何检索函数输入 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29647644/