请高手帮助,我在asp.net的设计界面写了javascript,可调用时“缺少对象”

evaELLIS 2004-04-14 10:08:32
<script language="javascript">
<!--

function SelectAllCheckboxes(spanChk){

// Added as ASPX uses SPAN for checkbox
var oItem = spanChk.children;
var theBox=oItem.item(0);
xState=theBox.checked;


elm=theBox.form.elements;
for(i=0;i<elm.length;i++)
if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
//elm[i].click();
if(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
}


function HighlightRow(chkB) {
var oItem = chkB.children;
xState=oItem.item(0).checked;
if(xState)
{chkB.parentElement.parentElement.style.backgroundColor='lightcoral';
chkB.parentElement.parentElement.style.color='white'; }else
{chkB.parentElement.parentElement.style.backgroundColor='white';
chkB.parentElement.parentElement.style.color='black'; }
}

function ForceError(msg, url, lno) {
alert("Error Occurred!Handled by Generic Error Handler" + "\n" +
"Error:" + msg + "\n" + "URL:" + url + "\n" +
"Line Number:" + lno);

return true;
}

window.onerror = ForceError;

// -->
</script>

我在界面中调用:
<asp:CheckBox name="chkAll" id="chkAll" onclick=" javascript:SelectAllCheckboxes(this);" runat="server" AutoPostBack=False
ToolTip="Select/Deselect All"></asp:CheckBox>
<INPUT onclick="javascript:SelectAllCheckboxes(this);" type="checkbox" id="dd">
为什么会“缺少对象”
...全文
46 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
evaELLIS 2004-04-14
  • 打赏
  • 举报
回复
onchange="if(this.parentElement.parentElement.style.backgroundColor!='red')this.parentElement.parentElement.style.backgroundColor='red';else this.parentelement.parentelement.style.backgroundcolor='white';"

问一下我这样有什么错误?
evaELLIS 2004-04-14
  • 打赏
  • 举报
回复
onclick="javascript:HighlightRow(this);" OnCheckedChanged="grdEmployees_CheckedChanged" onchange="if(this.parentElement.parentElement.style.backgroundColor!='red')this.parentElement.parentElement.style.backgroundColor='red';else this.parentelement.parentelement.style.backgroundcolor='white';"

问一下我这样有什么错误?
evaELLIS 2004-04-14
  • 打赏
  • 举报
回复
孟子E:
你有没有在题头有CheckBox的示例代码,
孟子E章 2004-04-14
  • 打赏
  • 举报
回复
var oItem = spanChk.children;
var theBox=oItem.item(0);
xState=theBox.checked;


elm=theBox.form.elements;
什么写法啊??

windowObj.document.formName.elements;
wudixiaocaoren 2004-04-14
  • 打赏
  • 举报
回复
JS放置的放置的位置有关,因为你可能在没有声明对像前就用到了JS里面的东西,你要把JS放在对像声明后面。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧