简体   繁体   English

JavaScript中的函数预期错误

[英]Function Expected Error in javascript

for dynamically created check box when it is clicked i want to grab the attribute value.It is working in IE 8,9,10 but not working in IE 11,chrome shows function expected error 单击时要动态创建的复选框,我想获取属性值。它在IE 8,9,10中有效,但在IE 11中无效,chrome显示功能预期错误

<input type=checkbox checked='checked' id='SymptomFailureCodeId' TabIndex='54' style='cursor:pointer;' onclick=ChkClickEvt(this);  FailureCodeId="1" >


function ChkClickEvt(Obj) { 
    alert(Obj.attributes("FailureCodeId"));
}

Try using getAttribute instead: 尝试改用getAttribute

Obj.getAttribute("FailureCodeId")

Or if you want to use attributes property don't use it as a method. 或者,如果您想使用attributes属性,请不要将其用作方法。 It's a NamedNodeMap . 这是一个NamedNodeMap

For example: 例如:

Obj.attributes["FailureCodeId"]

But be aware that this no longer supported on Firefox > 22 and many modern browsers. 但是请注意,Firefox> 22和许多现代浏览器不再支持此功能。 Read more about this at MDN MDN上了解有关此内容的更多信息

A better method would be using HTML5 data-* attributes . 更好的方法是使用HTML5 data- *属性

Markup 标记

<input type='checkbox' id='SymptomFailureCodeId' data-FailureCodeId="1" />

JavaScript JavaScript的

var article = document.querySelector('#SymptomFailureCodeId'),
          data = article.dataset;
console.log( data.FailureCodeId );

PS: You would be golden with this and this PS: 件事会让你很高兴

PPS: I am fairly sure that making up custom attributes like that is not the best practice. PPS:我相当确定,建立这样的自定义属性不是最佳实践。 I am searching for further evidence to back my argument. 我正在寻找进一步的证据来支持我的论点。 ;) ;)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM