简体   繁体   中英

jQuery code not working in Firefox/Chrome

var matcheduserID = $('.checkone')[1].matcheduserID;

<input type="checkbox" matcheduserID='user1' class="checkone" onclick="javascript:HoldItem('H')"> 

This code works in Internet Explorer, though in Firefox and Chrome I get it returns undefined.

I think you are trying to access the wrong element in the first place.. Are you trying to access the First element or the second element ..

The NodeList is 0 index based .

If it's the first element you are trying to access then use

var matcheduserID = $('.checkone')[0].matcheduserID;

Try using the .getAttribute() method

.get(1) gets the second element with the given class..

var matcheduserID = $('.checkone').get(1).getAttribute("matcheduserID");

Maybe you are encountering this issue because matcheduserID is not a default attribute for the element

jQuery

var matcheduserID = $('.checkone:eq(1)').attr('matcheduserID'); 

我认为您正在尝试这样做

matcheduserID = $('.checkone:first').attr('matcheduserID');

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