简体   繁体   中英

javascript error. uncaught ReferenceError

I am trying to write an anchor tag in a for loop, and sending parameters to a function in onclick event.

Now the problem is that the function does not pass the parameter which is in a variable instead it is getting an error "Uncaught ReferenceError: I is not defined ", where I is the value in the variable catidone.

catlisttxt += '<li>'+catidone+'<a href="#" onclick="return DisplayQues('+ catidone +')">'+data.categories[i].maincatname+'</a></li>';
catlisttxt += '<li>'+catidone+'<a href="#" onclick="return DisplayQues(\''+ catidone +'\')">'+data.categories[i].maincatname+'</a></li>';

Try escaping the quotes. I think when you do this, it actually sees this as DisplayQues(I) instead of DisplayQues('I')

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