bad*_*nda 0 javascript c# asp.net master-pages internet-explorer-8
我试图在用户点击Panel(在TableCell中)时运行此JS函数.此面板是内容页面中的元素,与主页面一起使用,主页面具有内容位置持有者.当我尝试单击面板时,会引发以下错误:
Microsoft JScript运行时错误:对象不支持此属性或方法
以下是Master页面ASPX的相关代码:
<link rel="Stylesheet" href="../includes/styles.css" />
<script type="text/javascript" language="javascript">
function swapDirections(control) {
var main = document.getElementByID('ct100_TableContent_' + control);
var long = document.getElementById('ct100_TableContent_' + control + '_long');
var short = document.getElementById('ct100_TableContent_' + control + '_short');
var mainhtml = main.innerHTML;
var longhtml = long.innerHTML;
var shorthtml = short.innerHTML;
if (mainhtml.length == shorthtml.length)
main.innerHTML = longhtml;
else
main.innerHTML = shorthtml;
}
</script>
Run Code Online (Sandbox Code Playgroud)
以下是"内容"页面的相关代码:
Panel rigDirections = new Panel();
rigDirections.CssClass = "clip";
rigDirections.ID = u.Id.ToString() + "_RD";
string MainDivRD = rigDirections.ClientID;
Literal rigDir = new Literal();
string sshort = "";
if (u.RigDirections.ToLower().Length > (textCutOFF + 4))
{
sshort = Server.HtmlEncode(u.RigDirections.ToLower().Substring(0, textCutOFF).Trim()) + " ...";
rigDir.Text = "<a class=RD_RA title=\"Click to Expand\" href=\"javascript: swapDirections('" + MainDivRD + "')\">" + sshort + "</a>"; ;
}
else
{
sshort = Server.HtmlEncode(u.RigDirections.ToLower().Trim());
rigDir.Text = sshort ;
}
string slong = Server.HtmlEncode(u.RigDirections.ToLower().Trim());
rigDirections.Controls.Add(rigDir);
cell.Controls.Add(rigDirections);
Run Code Online (Sandbox Code Playgroud)
和内容页面ASPX:
<asp:Content ID="Content1" ContentPlaceHolderID="TableContent" Runat="Server">
<asp:Panel ID="pnlTable" Width="950" runat="server">
</asp:Panel>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
错误被抛出在函数的第一行.
我已经用尽了我的网络搜索技能,而且之前从未使用过JS,所以如果有人有任何想法,我会非常感激他们.
谢谢!
badPanda
javascript区分大小写.document.getElementByID()不是一个功能,但是document.getElementById().
资本化问题.
document.getElementByID() //wrong
document.getElementById() //right
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17349 次 |
| 最近记录: |