简体   繁体   English

我一直在“无法获取未定义或空引用的属性”长度”

[英]I keep getting 'unable to get property 'length' of undefined or null reference'

I'm testing independent pieces of a larger piece of code for functionality in MS CRM and I want to know why I keep getting the above error for this small piece of code: 我正在测试较大代码段中的独立代码段,以了解MS CRM中的功能,并且我想知道为什么为什么对于这一小段代码却不断出现上述错误:

function testThis()
{
    var optionset = document.getElementById("new_makeyear");
    console.log("this is supposed to be something " + optionset.Options.length);
}

"new_makeyear" is an option set. “ new_makeyear”是一个选项集。 The log statement was just so I can see the behavior through the console. 日志语句只是为了让我可以通过控制台查看行为。 What's the problem? 有什么问题?

Thanks 谢谢

As Henk mentioned in his comment, you shouldn't access the DOM. 正如Henk在评论中提到的那样,您不应该访问DOM。 You should use the API to inspect the options of an option set, like this: 您应该使用API​​检查选项集的选项,如下所示:

function testThis() {
    var makeYear = Xrm.Page.getAttribute("new_makeyear");
    if (!makeYear) { return; }
    console.log(makeYear.getOptions().length + " options currently available");
}

如果您设法访问生成的DOM(例如通过onchange事件),则可以使用选项组, if(this.options[this.selectedIndex].parentNode.tagName =='optgroup') var og = this.options[this.selectedIndex].parentNode.label;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法获取未定义或空引用的属性“长度” - Unable to get property 'length' of undefined or null reference JavaScript运行时错误:无法获取未定义或空引用的属性“ length” - JavaScript runtime error: Unable to get property 'length' of undefined or null reference SCRIPT5007:无法获取未定义或空引用的属性“ length” - SCRIPT5007: Unable to get property 'length' of undefined or null reference IE 11无法获取未定义或空引用的属性“长度” - IE 11 Unable to get property 'length' of undefined or null reference 无法获取未定义或空引用的属性“未定义” - Getting Unable to get property 'undefined' of undefined or null reference 混淆获取此错误提示器无法获取未定义或空引用的属性“检查” - Confusion Getting this Errorr Unable to get property 'checked' of undefined or null reference 获取此错误 - 无法获取未定义或空引用的属性“mData” - Getting this error - Unable to get property 'mData' of undefined or null reference 尝试运行时出现“TypeError:无法获取未定义或 null 参考的属性‘年龄’” - Getting “TypeError: Unable to get property 'age' of undefined or null reference” when I try to run 为什么我得到“无法获取未定义或空引用的属性” pAmt”” - Why am i getting 'Unable to get property 'pAmt' of undefined or null reference' 无法获取未定义或空引用的属性“隐藏” - Unable to get property 'hide' of undefined or null reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM