This topic has been archived. It cannot be replied.
-
工作学习 / 学科技术讨论 / How to access DIV tag inside a contentplaceholder by javascript? Without the contentplaceholder, it seems working fine, but I can't access DIV tag after I have a master page with the contentplaceholder. Anyone can help? Thanks.
-ttaaoo(tao);
2008-11-10
(#4831809@0)
-
I assume that you are using document.getElementById(DIV_ID) in JavaScript on client-side and in the DIV tag you have runat =”server” attribute. When you use master page, you should use server control’s ClientID rather than ID .
-deep_blue(BLUE);
2008-11-11
(#4832548@0)
-
I didn't have runat="server" attribute though?
-ttaaoo(tao);
2008-11-11
(#4832670@0)
-
Then, there shouldn’t any difference with and without master page.
-deep_blue(BLUE);
2008-11-11
(#4832743@0)
-
var span = spanExists(spanID);
if (span) {....}function spanExists(spanID)
{
var idRegExp = new RegExp("(_" + spanID + ")$");
var spanList = document.getElementsByTagName("span");
for (var iIndex=0; iIndex<spanList.length; iIndex++)
{
if (idRegExp.test(spanList[iIndex].id))
return spanList[iIndex];
}
}
-c1xwy(洪兴罩俺去战斗);
2008-11-11
{311}
(#4832753@0)
-
用浏览器打开你的网页,看看源码就都明白了。放到placeholder里的对象 .Net 会自动改ID.比如 <asp:Button runat="server" ID="btnSubmit">
放到placeholder里面,你一看源码,会发现
<input type="submit" name="ctl00$plMain$btnSubmit" id="ctl00_plMain_btnSubmit" />
你的javascript 如果 用 btnSubmit 去找这个input,当然找不到。
-holdon(again);
2008-11-11
{251}
(#4834604@0)