简体   繁体   中英

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

<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:

Obj.getAttribute("FailureCodeId")

Or if you want to use attributes property don't use it as a method. It's a NamedNodeMap .

For example:

Obj.attributes["FailureCodeId"]

But be aware that this no longer supported on Firefox > 22 and many modern browsers. Read more about this at MDN

A better method would be using HTML5 data-* attributes .

Markup

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

JavaScript

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

PS: You would be golden with this and this

PPS: I am fairly sure that making up custom attributes like that is not the best practice. I am searching for further evidence to back my argument. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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